简体   繁体   中英

vb.net - Populating a combobox with multiple properties from object

Using vb.net (vs2005), how do I populate a combo box with multiple property values from an object? Right now I'm iterating a collection of objects and adding the name property of each object to the combo box. I'd like to add multiple properties from the object to the list. For now, I'd be happy if they appeared comma separated in the list.

Private _items As New List(Of Person)  'you will need to fill this with data!'

Private Sub Populate()

  For i As Integer = 0 To _items.count - 1
    lst.items.add(_items(i).Name & ", " & _items(i).Age)
  Next

End Sub

This will populate your listbox (which i have called lst) something like this:

Dave, 18
John, 21
Morgan, 23
Jen, 19

如果这是Winforms环境,请重写ToStirng()方法,然后将整个对象添加到items集合中。

You can either override the method by yourself. Or you are lazy like me. Try this multi column combo box
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM