Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,
i have a little problem as i m a nerd. i have this task to do.

i have a form to find the customer details and on the double click of the selected customer on gridview, its details should pass into the opened winform but as i know only frm.show or frm.showdialogue which opens a complete new winform which is not what i have wanted . please help me out.......thanks


i have a code here like this

C#
Form_OrderEntry frm = new Form_OrderEntry();
            frm.txtcustomercode.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            frm.txtcustomername.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            frm.Visible = true;
            this.Close();



form_orderentry is my main form and it should get values in its customercode and name textbox. but i get a complete new window.
Posted
Updated 14-Dec-12 1:18am
v2

On ur dataGridViewCell_Click event write the code of { } block,given below
C#
public void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
frm.txtcustomercode.Text = dataGridView1.Rows[e.RowIndex].Cells["ColumnNameOf_CustomerCode"].Value.ToString();

frm.txtcustomername.Text =dataGridView1.Rows[e.RowIndex].Cells["ColumnNameOf_CustomerName"].Value.ToString();
          
}
 
Share this answer
 
v2
Have a public static variable in the orderenter form,Find the opended orderenter by like this
Use FormCollection class to get the openned form object.
C#
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
  if(frm.name=="orderenter")
{
frm.Myvalue= customerdetails;

}
}


or
Have public static method in orderenter and pass the value as parameter

C#
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
  if(frm.name=="orderenter")
{
frm.showform(customerdetails);
}

// In the orderenter form have show showform method
public static void showform(customerdetails)
{
txtcustomercode.Text =customerdetails;
}

}
 
Share this answer
 
v2
Comments
bishnu karki 18-Dec-12 5:36am    
I finally did this my self guys.. here is the link to find out how i solved this problem ..
http://www.youtube.com/watch?v=VRvimdsfbTc


please check it out...and comment
As I understand,
Form1 ---> Form2 (now when it close pass result to already opened form1 again)


you should do this in your form2

-> In form2 (in which you have write methoddeclare form level public variables Return_Cust_code,Return_Cust_Nm
-> now set that variables in form close method instead of that new form opening code you have mention in question
C#
Return_Cust_code = dataGridView1.CurrentRow.Cells[0].Value.ToString();
Return_Cust_Nm = dataGridView1.CurrentRow.Cells[1].Value.ToString();
this.DialogResult= Dialogresult.ok;
this.Close();

-> now in Form1 receive these varibles like this
C#
Form1 frm = new Form1();
if (frm.ShowDialog() == Dilogresult.OK)
{
   string cc = frm.Return_Cust_code;
   string cn = frm.Return_Cust_Nm;
}

Happy Coding!
:)
 
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