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);
}
精彩评论