bdr bdr - 1 month ago 12
C# Question

How can i show all my DataSets in a ComboBox

How can i populate my ComboBox with all the datasets that are in my project

My Code

foreach (DataTable table in DataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
object item = row[column];

}
}
comboBox1.Items.Add(table.TableName);
}

Answer

You need to fill the combobox with tableNames only.

foreach (DataTable table in DataSet.Tables)
        {
            comboBox1.Items.Add(table.TableName);
        }

Then you need to code the Select event of your combobox which could look something like this.

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
    //fill listview with items that belong to the combobox.SelectedItem
    //since you filled the combobox with table.TableName, the name will be in .SelectedItem
}

And don't forget

this.comboBox1.SelectedIndexChanged += new System.EventHandler(comboBox1_SelectedIndexChanged);
Comments