简体   繁体   English

vb.net-使用对象的多个属性填充组合框

[英]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? 使用vb.net(vs2005),如何用对象的多个属性值填充组合框? Right now I'm iterating a collection of objects and adding the name property of each object to the combo box. 现在,我正在迭代对象的集合,并将每个对象的name属性添加到组合框中。 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: 这将填充您的列表框(我称为lst),如下所示:

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 http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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