开发者

How to add values to listbox?

开发者 https://www.devze.com 2023-01-03 23:56 出处:网络
I have Datatable collected with my Column Names.. I want to add them in listbox.. Many column are there.. So need to us开发者_如何学Pythone For each how can i achieve thisusing DisplayMember and Value

I have Datatable collected with my Column Names.. I want to add them in listbox.. Many column are there.. So need to us开发者_如何学Pythone For each how can i achieve this


using DisplayMember and ValueMember

DataTable dt = ds.Tables[0];

// 1. set DisplayMember and ValueMember
lbSiteCode.DisplayMember = dt.Columns[0].ColumnName;
lbSiteCode.ValueMember = dt.Columns[1].ColumnName;
// 2. set DataSource
lbSiteCode.DataSource = dt;


DataColumnCollection columns = ds.Tables[0].Columns;
foreach (DataColumn column in columns)
{
    listBox1.Items.Add(column.ColumnName);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消