[RESOLVED] Inherit ComboBox class to add TAG property for each item
I expected to find the TAG property for each item in the ComboBox. Since, there is not, I now expect it can herited to add the property.
Re: Inherit ComboBox class to add TAG property for each item
Well, no. The items are all strings, however you can add objects instead of just strings to the ComboBox, these objects can have a Tag property (or any property you would like to give it).
Code:
Public Class MyListItem
Public Property Text As String
Public Property SomeOtherValue As Integer
End Class
'somewhere else in your code
Dim myItem As New MyListItem
myItem.Text = "Hello"
myItem.SomeOtherValue = 32
ComboBox1.DisplayMember = "Text" 'Make sure the Text property is used to display the item
ComboBox1.Items.Add(myItem)
'....
Dim x As Integer = DirectCast(ComboBox1.SelectedItem, MyListItem).SomeOtherValue
Edit This assumes you're talking about the Windows Forms ComboBox.
Re: Inherit ComboBox class to add TAG property for each item
Serves my purpose, perfectly. Thanks!
Re: Inherit ComboBox class to add TAG property for each item
Glad I found this, thanks!
How can I select a comboboxitem programatically based on this SomeOtherValue property?