Question

I am using a ToolStripComboBox to list some data. I am populating this combo with some custom objects:

For Each obj As myObject In myObjectList
    myToolStripComboBox.Items.Add(obj)
Next

This works great except the text displayed in the combo is the name of the object class. I can understand why and realise that I need to do something to make the combo use a property from my class instead.

The help files state:

To add objects to the list at run time, assign an array of object references with the AddRange method. The list then displays the default string value for each object. You can add individual objects with the Add method.

The bit in bold suggests I need to setup the default string value in my class. How would I go about doing this?

Was it helpful?

Solution

You need to add an Overrides ToString to your myObject class :

Public Overrides Function ToString() As String
    --return whatever you want to display
End Function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top