开发者

How to add values to listbox?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜