How do I do an ItemData for a combobox in VB.Net?
Printable View
How do I do an ItemData for a combobox in VB.Net?
One way you can do it is to create your own comboitem class like so:
VB Code:
Public Class clsCboItem Public sVal As String Public lData As Long Overrides Function ToString() As String Return sVal End Function End Class
Then when you are adding to the combo box, you do this:
VB Code:
Dim t As New clsCboItem t.sVal = "A" t.lData = 56 ComboBox1.Items.Add(t) t = Nothing t = New clsCboItem t.sVal = "C" t.lData = 69 ComboBox1.Items.Add(t) MsgBox(ComboBox1.Items(0).ldata)
Hi,
I am new to this. Where do I place that code and is that the actual code that will work?
Thank You
Add a new class to your app via Project->Add Class and call it clsCboItem. Then place the class code in that module.
The other code was just an example on how to use it. You can place that in a button click event.