怎样动态循环给list赋值呢
lsp69 2015-12-09 12:52:30 有以下代码 :
public partial class Form1 : Form
{
public class ComboBoxMember
{
public string Id
{
get;
set;
}
public string Text
{
get;
set;
}
}
List<ComboBoxMember> list = new List<ComboBoxMember>();
public Form1()
{
InitializeComponent();
list = new List<ComboBoxMember>() {
new ComboBoxMember(){ Id="0", Text="张三a"},
new ComboBoxMember(){ Id="1", Text="李四abc"},
new ComboBoxMember(){ Id="2", Text="张三三adbx"},
new ComboBoxMember(){ Id="3", Text="李四四"},
new ComboBoxMember(){ Id="4", Text="张张三"},
new ComboBoxMember(){ Id="5", Text="李李四"}
};
comboBox1.Items.AddRange(list.ToArray());
comboBox1.DisplayMember = "Text";
comboBox1.ValueMember = "Id";
}
}
其中有这里面的数据,我是从数据库直接获取到的DataTable列表,怎样放入到list里呢?
以下目前是写死固定的。
list = new List<ComboBoxMember>() {
new ComboBoxMember(){ Id="0", Text="张三a"},
new ComboBoxMember(){ Id="1", Text="李四abc"},
new ComboBoxMember(){ Id="2", Text="张三三adbx"},
new ComboBoxMember(){ Id="3", Text="李四四"},
new ComboBoxMember(){ Id="4", Text="张张三"},
new ComboBoxMember(){ Id="5", Text="李李四"}
};