将列表框绑定到List< object>在WinForms中 [英] Binding Listbox to List<object> in WinForms
本文介绍了将列表框绑定到List< object>在WinForms中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将列表框绑定到Windows窗体中的对象列表的最简单方法是什么?
What's the simplest way to bind a Listbox to a List of objects in Windows Forms?
推荐答案
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()
.
这篇关于将列表框绑定到List< object>在WinForms中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文