怎样动态循环给list赋值呢

浩方软件HFWMS 浩方软件HFWMS 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有以下代码 :
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="李李四"}
};



...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
浩方软件HFWMS
C# 111,130 成员 642,539 内容