Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tab pages on winforms. In tab2 data is fetched in a datagridview from a database. In tab1, I've a combobox [sales analyse]which makes a user to select an option. I now want to get access to tab2 from tab1 on combobox selection, displaying me a regional sales information from the data in tab2 datagrid. Is it possible? I don't really know where to start.

C#
private void cb1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
if (cbAnalyse.SelectedIndex == cb1.FindStringExact("Sales anylse")) 
  { 


  }
}


tab1 image
[^]

tab2 image
[^]

ExAMPLE:
In my DVG in the column sales13, the values for north are 2x 800. So the txtBox for north in tab1 should display 1600 and so for the rest.

EXPECTION:
1. Select an option in combobox
2. Go through the DGV using a where function or ???
3. Display results in the appropriate textbox fields
Posted
Comments
MJ2014 26-Jun-15 12:45pm    
can please tell me what you want to do. so that i can help..you just want tab page2 dgv data into tab page 1 text is it correct?

1 solution

in my example i have added 2 tabs . in 2nd tab added datagridview and in first tab text box. after tabindex change you will get data in text box. code is given below

C#
private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.Columns.Add("col1", "Test");
        dataGridView1.Columns.Add("Col2","Result");
        string[] newstring=new string[]{"North","333"};

        dataGridView1.Rows.Add(newstring);
        newstring = new string[] { "East", "444" };
        dataGridView1.Rows.Add(newstring);
        newstring = new string[] { "Northeast", "555" };
        dataGridView1.Rows.Add(newstring);

    }

    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {

        foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
            if (dr.Cells[0].Value != null)
            {
                if (dr.Cells[0].Value.ToString() == "North")
                {
                    textBox1.Text = dr.Cells[1].Value.ToString();
                }
            }
        }
    }
}
 
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