且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将列表框绑定到列表<对象>在 WinForms 中

更新时间:2022-05-22 03:07:34

您正在寻找 数据源属性:

You're looking for the DataSource property:

List<SomeType> someList = ...;
myListBox.DataSource = someList;

您还应该将 DisplayMember 属性设置为您希望列表框显示的对象中的属性名称.如果不这样做,它将调用 ToString().

You should also set the DisplayMember property to the name of a property in the object that you want the listbox to display. If you don't, it will call ToString().