Click here to Skip to main content
11,805,604 members (56,200 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Windows Application
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 at 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 at 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 at 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
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2015
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