开发者

ToolStripComboBox + objects default string value

开发者 https://www.devze.com 2022-12-22 22:25 出处:网络
I am using a ToolStripComboBox to list some data. I am开发者_如何学Go populating this combo with some custom objects:

I am using a ToolStripComboBox to list some data. I am开发者_如何学Go 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消