怎样动态循环给list赋值呢
有以下代码 :
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="李李四"}
};
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="李李四"}
};
...全文
相关推荐
python 循环数据赋值实例
今天小编就为大家分享一篇python 循环数据赋值实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Vue.js 动态为img的src赋值方法
下面小编就为大家分享一篇Vue.js 动态为img的src赋值方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
C++STL list用法与实现[代码]
本文详细介绍了C++STL中list容器的用法和底层实现。list是一种序列式容器,底层采用带头双向循环链表实现,支持高效的插入和删除操作。文章从list的创建开始,详细讲解了节点类、构造函数、拷贝构造函数、赋值重载、析构函数等基本框架的实现。接着介绍了运算符重载(++、--、==、!=、*、->)、迭代器相关函数、插入和删除函数(insert、erase、push_front、pop_back等)以及其他函数(size、clear、swap)的实现。最后,文章对比了list的sort与库的sort的效率差异,并解释了list为何需要自己实现sort函数。通过迭代器类的封装,用户可以通过统一的接口访问list容器,而无需关心底层实现细节。
P215~222C++list容器学习笔记.docx
P215~222C++list容器学习笔记.docx
试论动态开发语言Python研究.pdf
试论动态开发语言Python研究.pdf


