Click here to Skip to main content
15,886,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have form1 that have text boxes and button this button open form2 that have data grid view , i want when i do double click in row this row display in the form1

C#
private void button1_Click(object sender, EventArgs e)
{
    FRM_DRIVERS_LIST frm = new FRM_DRIVERS_LIST();
    frm.ShowDialog();
    ID = Convert.ToInt32(frm.dGV_Driver.SelectedRows[0].Cells[0].Value);
    this.txt_code.Text = frm.dGV_Driver.SelectedRows[0].Cells[1].Value.ToString();
    this.txt_Driver_Name.Text = frm.dGV_Driver.SelectedRows[0].Cells[2].Value.ToString();
    this.txt_Tel1.Text = frm.dGV_Driver.SelectedRows[0].Cells[3].Value.ToString();
    this.txt_Tel2.Text = frm.dGV_Driver.SelectedRows[0].Cells[4].Value.ToString();
    this.txt_Address.Text = frm.dGV_Driver.SelectedRows[0].Cells[5].Value.ToString();
    this.dtp_S_work.Text = frm.dGV_Driver.SelectedRows[0].Cells[6].Value.ToString();
    this.CB_WorkPlace.Text = frm.dGV_Driver.SelectedRows[0].Cells[7].Value.ToString();
    this.CB_License_type.Text = frm.dGV_Driver.SelectedRows[0].Cells[8].Value.ToString();
    this.dTP_Date_e_License.Text = frm.dGV_Driver.SelectedRows[0].Cells[9].Value.ToString();
    txt_code.ReadOnly = true;
    btn_Edite.Enabled = true;
    btn_Delete.Enabled = true;
    btn_Add.Enabled = false;
}

form2 that have data grid view :-

private void dataGridView_Driver_DoubleClick(object sender, EventArgs e)
{
    this.close();
}
Posted
Updated 12-Jan-16 0:34am
v2
Comments
HobbyProggy 12-Jan-16 6:01am    
Have you tried anything so far?
Could you show us your Codeparts where the Function is seated?

Mainly from what you say i guess you just have to fire an event on the doubleClick and return/send the Text to your Form1.
Member 12244977 12-Jan-16 6:11am    
in form1 that have text box :-
private void button1_Click(object sender, EventArgs e)
{
FRM_DRIVERS_LIST frm = new FRM_DRIVERS_LIST();
frm.ShowDialog();
ID = Convert.ToInt32(frm.dGV_Driver.SelectedRows[0].Cells[0].Value);
this.txt_code.Text = frm.dGV_Driver.SelectedRows[0].Cells[1].Value.ToString();
this.txt_Driver_Name.Text = frm.dGV_Driver.SelectedRows[0].Cells[2].Value.ToString();
this.txt_Tel1.Text = frm.dGV_Driver.SelectedRows[0].Cells[3].Value.ToString();
this.txt_Tel2.Text = frm.dGV_Driver.SelectedRows[0].Cells[4].Value.ToString();
this.txt_Address.Text = frm.dGV_Driver.SelectedRows[0].Cells[5].Value.ToString();
this.dtp_S_work.Text = frm.dGV_Driver.SelectedRows[0].Cells[6].Value.ToString();
this.CB_WorkPlace.Text = frm.dGV_Driver.SelectedRows[0].Cells[7].Value.ToString();
this.CB_License_type.Text = frm.dGV_Driver.SelectedRows[0].Cells[8].Value.ToString();
this.dTP_Date_e_License.Text = frm.dGV_Driver.SelectedRows[0].Cells[9].Value.ToString();
txt_code.ReadOnly = true;
btn_Edite.Enabled = true;
btn_Delete.Enabled = true;
btn_Add.Enabled = false;
}
form2 that have data grid view :-

private void dataGridView_Driver_DoubleClick(object sender, EventArgs e)
{
this.close();
}

when i double click on the row its display . but when i close form one he display the first row withoud i double click in this row
HobbyProggy 12-Jan-16 6:39am    
Okay, your code is a little messy (at least for my eyes). In your main Form when you click the button you display the data from the grid right?
The second Form is just a Datagrid that shows some values?

And if you close Form 1 your Grid does what? I'am sorry i don't understand it.
Member 12244977 12-Jan-16 6:51am    
when i close the form 2 that have data grid view the first row display in form1 that have text box without i double click in the rows or without i select the row i want display in the form1
HobbyProggy 12-Jan-16 7:37am    
Yes okay, but that is a normal behivour, you close your grid form and don't delete the data in form so it will stay there since you don't hand your form 1 references but "hard" values. If you close form 2 you would have to clear the data in form 1 and that should do the trick you want to, then everything there is empty

For eg: You are using Form1 & Form2. You need to pass value from Form1 to Form2.

Create one constructor in the Form2

as

C#
public Form2(string txt1)
    {
        InitializeComponent();
        textBox1.Text = txt1;

    }


Then Form1 Button Click


C#
Form2 frm2 = new Form2(txt_Driver_Name.Text);
frm2.Show(); 
 
Share this answer
 
According to the comments i suggest you to try the following:

Your Form2 needs to know Form1 therefore

public FRM_DRIVERS_LIST()
{
InitializeComponent();
this.dGV_Driver.DataSource = clsDriver.GET_ALL_DRIVERS();
dGV_Driver.Columns[0].Visible = false;
}


Should be changed into

public FRM_DRIVERS_LIST(Form InYourForm1)
{
InitializeComponent();
this.dGV_Driver.DataSource = clsDriver.GET_ALL_DRIVERS();
dGV_Driver.Columns[0].Visible = false;
yourForm1 = YourForm1
}


Then you can clear the data in Form 1 when closing

private void dGV_Driver_DoubleClick(object sender, EventArgs e)
{
yourForm1.ClearData();
this.close();
}


The ClearData() Method could look like this

public void ClearData()
{
this.txt_code.Text = "";
this.txt_Driver_Name.Text = "";
this.txt_Tel1.Text = "";
this.txt_Tel2.Text = "";
this.txt_Address.Text = "";
this.dtp_S_work.Text = "";
this.CB_WorkPlace.Text = "";
this.CB_License_type.Text = "";
this.dTP_Date_e_License.Text = "";
}


Then the data in Form1 should be cleared

Please try this out and tell me if it helped. Otherwise we can work on a different solution :)
 
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