Search code examples
c#datagridviewtextbox

Value of Selected dataGridView cell in Textbox


i have a datagridview and textbox in windows form,when i click on a cell of the datagridview the value must copy to the textbox.

I am getting a error:

System.Windows.Forms.DataGridCell Does not contain a definition for RowIndex

I have tried this code

void dataGridView1_Click(object sender, EventArgs e)
 {
      Txt_GangApproved.Text=dataGridView1.CurrentCell.RowIndex.Cells["NO_OF_GANGS_RQRD"].Value.ToString();
 }

Solution

  • foreach (DataGridViewRow RW in dataGridView1.SelectedRows) {
        //Send the first cell value into textbox'
        Txt_GangApproved.Text = RW.Cells(0).Value.ToString;
    }