Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two different tables and a combo box,

I trying to write the code so that (for example) if I select "sweets" in the combo box, the sweets table is displayed in the dataGridView1, and if I select "Chocolate" the chocolate table is displayed in the dataGridView1 instead.

So far all i have for code is ....
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedText == "Sweets")
            {
                DataGridView = SweetsInventoryDataSet;
            }

Is it possible to do this?

What I have tried:

C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedText == "Sweets")
            {
                DataGridView = SweetsInventoryDataSet;
            }
Posted
Updated 8-Feb-18 6:55am
v2
Comments
Ziee-M 8-Feb-18 10:26am    
You are in the right direction, keep going.
Fews corrections : to set a grid data, you need to use its DataSource propertie, and call databound after that.
DataGridView.DataSource = SweetsInventoryDataSet;
DataGridView.DataBind();

1 solution

Simple correction:
C#
DataGridView.DataSource = SweetsInventoryDataSet;


For further details, please see:
DataGridView.DataSource Property (System.Windows.Forms)[^]
How to: Bind Data to the Windows Forms DataGridView Control | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900