Mahmoud Omar

Mahmoud Omar

  • NA
  • 4
  • 1.2k

how i display data from gridview to textbox in another form?

Feb 10 2016 3:19 AM
I create form1 that have textbox and button that open form2 that have gridview , when i close gridview the first row display in textbox without i double click in the row, How i solve this problem ?
 
this is code in form 1 that have textbox and button1 is response to open form2 :-
 
public FRM_DRIVERS()
{
InitializeComponent();
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();
this.txt_Notes.Text = frm.dGV_Driver.SelectedRows[0].Cells[10].Value.ToString();
txt_code.ReadOnly = true;
btn_Edite.Enabled = true;
btn_Delete.Enabled = true;
btn_Add.Enabled = false;
}
code in form2  that have gridview:- 
public FRM_DRIVERS_LIST()
{
InitializeComponent();
this.dGV_Driver.DataSource = clsDriver.GET_ALL_DRIVERS();
dGV_Driver.Columns[0].Visible = false;
dGV_Driver.Columns[10].Visible = false;
}
private void dGV_Driver_DoubleClick(object sender, EventArgs e)
{
this.Close();
}
 
 

Answers (2)