Posts Tagged ‘object item’
How to add object to a combobox
To add the object as an item to a combobox is pretty easy, it is the same as you are adding a string/numeric value.
Example:
-
Public class X
-
Public Name as String
-
Public Value as String
-
-
Public Sub New(StrName As String, StrValue As String)
-
Name = StrName
-
Value = StrValue
-
End Sub
-
End Class
-
-
To fill the combobox with the created object, let's say you have a combo box called cboX
-
dim Obj as X
-
For i as Integer = 0 to 10
-
cboX.Items.Add(New X("Name " & i.ToString(), "Value " & i.ToString())
-
Next
Then you need to set the DisplayMember property of the Combo box so that the Text displayed in the
combobox is not “namespace.X”.
-
cboX.DisplayMember = "Name"