views:

242

answers:

1

This might be a bit of a dumb question, but I'm trying to add some extra key/value pairs to a combo box using VB.NET. The initial item list is generated from a hashtable, which contains a collection of objects.

I've managed to add the extra values to the box using the Add method, however I now run into problems when reading back the selected item from the combo box because some list items are objects, while others are strings.

My best option seems to be to load the initial data as key/value pairs by looping through the hashtable, however this doesn't seem to be working too well either because I'm still getting errors.

I'm getting frustrated because it's taking me hours to do something that should take 5 minutes!

I'll post some sample code if it will help.

A: 

You could check the type of SelectedItem on the combo box, and use that to determine whether you are dealing with one of your objects or not.

If TypeOf myComboBox.SelectedItem Is GetType(ObjectClass) Then

Else

End If
Purple Ant
Great - should have thought of that one myself! Have altered the code it's working well. Thanks for your help.
Billious