VB.Net Combobox/Listbox Control

Brent Alan

Newcomer
Joined
Dec 31, 1969
Messages
5
Location
Moncton, NB, Canada
In VB6 these controls had a very useful ItemData property, that I would use to hold an ID. With the new version .Net these controls have been changed and this property is no longer available.

When my form loaded the control would display all my contacts (list would hold the Person Name and the ItemData property would hold the ID), when I selected a person the ID would be passed from the ItemData property to the method that brought back complete details about that person.

Is there a technique with the .Net Combobox control that would allow me to continue with this approach?

Thanks

Brent
 
The Add method of the Items collection takes an Object type, in other words anything. Create a class that is able to hold the data that you need for each item and add that to the Items collection instead of a string. Just make sure the class overrides ToString, as that is what will be displayed in the ListBox/ComboBox.
 
Hi Derek.

I tried that earlier.

In the Combobox control I had the name and ID displaying, by overridding my object's ToString() method (as you mentioned), then I just extracted the ID portion out when I selected the person from the list.

So this is the best approach? This will work fine, but I had grown to like the the old ItemData property...

Thanks for the reply....its good to know that I'm on the correct track.

Brent
 
Back
Top