Click here to Skip to main content
13,050,896 members (61,510 online)
Rate this:
Please Sign up or sign in to vote.
Hello all,

I really want to know how can I pass a whole datagridview values to another datagridview in another form? using c# windows application.

i have two form ,

i have one search option which is have,
one text box and one search button,
when i type something related to the table field in my text box and click search button,

the corresponding data has displayed to another form datagridview, that means form2.


i have only datagridview.

please my code see below where i did mistake my code and let me know the solution please..

my code is:


private void button1_Click(object sender, EventArgs e)
            if (textBox1.Text == "")
                 MessageBox.Show("Please Enter the Input Key.", "Error Message");
                 DataTable dataTable = new DataTable();
                 con = new SqlConnection(s);
                 cmd = new SqlCommand("select Destinations,TimeofDay,DialCode,EffectiveDate,NewOffer from RateSheets where Destinations='" + textBox1.Text + "'", con);
                 SqlDataReader sqlDataReader = cmd.ExecuteReader();
                 form2 fm = new testing();
                 dataGridView1.DataSource = dataTable;
       catch (Exception ex)

Thanks in advance...
Posted 26-Feb-13 2:29am
Orcun Iyigun 26-Feb-13 8:43am
maybe you may want to change your where statement with LIKE '%textbox1.text%' instead of equals. In your current code do you have any exceptions?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Member 9989542 18-Apr-13 0:54am
i have two tables sql (database name vijay)
table1 table2

name age sex name marks1 marks2 total
vijay 15 m vijay 50 45 95
ramu 14 m vijay 45 60 105
ram 15 m ram 50 45 95
lux 15 f ramu 50 45 95
ramu 50 55 105
lux 50 45 95

i make these two tables in two gridview in c# windows form
nw when i click the 1st gridview row (name) , i need to filter name which present in second gridview and show that data in secondgridview
i need a stored procedure and need to call that in c#...

when i click name vijay in firstgridview i need like below in secondgridview
name marks1 marks2 total
vijay 50 45 95
vijay 45 60 105
Orcun Iyigun 18-Apr-13 2:36am
why would you need to do the binding in the stored procedure?? HAve a look at this link[^]. It is gridview's click events. You can use cell click event and on this event you can bind your second gridview to filter your results. It is more easier in my opinion.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100