C#中 combobox 如何绑定数组
C#中 combobox 如何绑定数组?
------解决方案--------------------public class ListItem
{
private string textField;
public string TextField
{
get { return textField; }
set { textField = value; }
}
private string valueField;
public string ValueField
{
get { return valueField; }
set { valueField = value; }
}
}
//下面绑定
System.Collections.ArrayList list = new System.Collections.ArrayList();
for (int i = 0; i < 10; i++)
{
MyListItem listItem = new MyListItem();
listItem.TextField = "Text " + i;
listItem.ValueField = i.ToString();
list.Add(listItem);
}
combobox.DataSource = list;
combobox.DisplayMember = "TextField ";
combobox.ValueMember = "ValueField ";