ListBox绑定一个对象

转自原文 C#中ListBox的Items属性是Object对象,如何显示该对象的别名 而真正的则保存在其他的地方

 

一般是datasource 绑定一个list对象

list 可以是 自定义类型的对象

 

如:

class Person

{

INT ID;

STRING NAME

}

 

list<Person> listps = new list<Person>();

 

dataSource = listps ;

ListBox.DislayMember = "Name";

ListBox.ValueMember = "ID";

 

Person selPerson = (Person)ListBox.SelectedItem;

int nSelectedID = (int)ListBox.SelectedValue;

 

//do somethings ……

 

 

 

原文地址:https://www.cnblogs.com/arxive/p/6598891.html