|
-
Jan 19th, 2013, 10:29 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Jan 19th, 2013, 10:52 AM
#2
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.
Last edited by Joacim Andersson; Jan 19th, 2013 at 10:58 AM.
-
Jan 19th, 2013, 11:03 AM
#3
Thread Starter
Hyperactive Member
Re: Inherit ComboBox class to add TAG property for each item
Serves my purpose, perfectly. Thanks!
-
Sep 23rd, 2015, 03:08 AM
#4
New Member
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?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|