1

I have Datatable collected with my Column Names.. I want to add them in listbox.. Many column are there.. So need to use For each how can i achieve this

1
  • 1
    Are you using Windows Forms, WPF, ASP.Net? Commented Jun 21, 2010 at 9:50

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

@Shiny: You're asking how to add the columns to a ListBox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.