Copy DataGridView values to TextBox

后端 未结 3 2168
旧时难觅i
旧时难觅i 2020-11-22 13:19

I have tried to get an answer to this but so far no help has been able to do what I want it to.

I have this piece of code, which is meant to look at the selected row

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 14:12

    If you want to display the datagridview selected rows into corresponding textboxes, fine the below steps ,

    Step 1: 1. Change the DataGridView Selection mode to FullRowSelect in Datagridview property. 2. Create the cell click event in Data grid view using property. enter image description here 3. Write the below code and test it, It may helpful

    private void DataGridView01_CellClick(object sender,DataGridViewCellEventArgs e)
    {
    if (DataGridView01.Rows.Count > -1)
    {
    PersonIdTextBox.Text=DataGridView01.Rows[e.RowIndex].Cells[0].Value.ToString();
    comboBox1.Text = DataGridView01.Rows[e.RowIndex].Cells[1].Value.ToString();
    Txt_FirstName.Text = DataGridView01.Rows[e.RowIndex].Cells[2].Value.ToString();
     mIDDLENAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[3].Value.ToString();
    sURNAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[4].Value.ToString();
    cITYTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[5].Value.ToString();
    eMAILTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[6].Value.ToString();
    
    }
    }
    

提交回复
热议问题