ComboBoxItem text ve value değerlerini alan class ımız. Kodunu aşağıda bulabilirsiniz.
'--------------------------------------------------------------
Dim lstMonths As New List(Of ComboBoxItem)
lstMonths.Add(New ComboBoxItem("January", 1))
lstMonths.Add(New ComboBoxItem("February", 2))
lstMonths.Add(New ComboBoxItem("March", 3))
lstMonths.Add(New ComboBoxItem("April", 4))
lstMonths.Add(New ComboBoxItem("May", 5))
lstMonths.Add(New ComboBoxItem("June", 6))
lstMonths.Add(New ComboBoxItem("July", 7))
lstMonths.Add(New ComboBoxItem("August", 8))
lstMonths.Add(New ComboBoxItem("September", 9))
lstMonths.Add(New ComboBoxItem("October", 10))
lstMonths.Add(New ComboBoxItem("November", 11))
lstMonths.Add(New ComboBoxItem("December", 12))
'cbMonths is a combobox
cbMonths.DataSource = lstMonths
cbMonths.DisplayMember = "Text"
cbMonths.ValueMember = "Value"
'--------------------------------------------------------------
Public Class ComboBoxItem
Private _value As Object
Public Property Value() As Object
Get
Return _value
End Get
Set(ByVal CValue As Object)
_value = CValue
End Set
End Property
Private _text As String
Public Property Text() As String
Get
Return _text
End Get
Set(ByVal CValue As String)
_text = CValue
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal text As String, ByVal value As Object)
Me.Text = text
Me.Value = value
End Sub
Public Overrides Function ToString() As String
Return Text
End Function
End Class
'--------------------------------------------------------------
Add Items with value and display into comboboxes in VB.Net
No comments:
Post a Comment