How to pass cell values from a datgridview to another form in c#!

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi!
I am designing a form which contains a datagridview which can display all customer orders. I also have a button inside the datagridview so that if a user clicks the button it will open another form which contains the items which the customer ordered in a
datagridview.
I am using the code below on the first form.
<pre class="prettyprint private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

Item i = new Item();
i.Show();



}[/code]
Item is the name of the second form.
The second form contains the following code in the form load event.
<pre class="prettyprint SqlConnection con = new SqlConnection(Properties.Settings.Default.Stock_ControlConnectionString);
try
{
con.Open();
}
catch (Exception)
{
MessageBox.Show("Error with the database Connection");
}
try
{
string query = "Select * From Order_Items_Table ";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception)
{
MessageBox.Show("Error Occured");
}

}[/code]
<br/>
The code in the second form will display all the items on the Order Items Table. I want a c# code which can pass the orderID value which is the first cell value in the datagrid from the first form to the second form so that the item form will display the
data according to the orderID
I hope someone can help me out in this.
Thanks in advance. <hr class="sig *mirfath*

View the full article
 
Back
Top