Get the value of one cell from a DataGridView?

  • Thread starter Thread starter Edwin Smith
  • Start date Start date
E

Edwin Smith

Hello:

I have a DataGridView control and I want to doubleclick a row and get a
single cell value.

Here's a snippet:

private void pATIENTSDataGridView_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)

{

textbox1.Text = [the contents of the cell at column4 of the row that was
doubleclicked]

}

This should be a simple task but I can't seem to get it.

Thanks

Edwin
 
Edwin Smith said:
private void pATIENTSDataGridView_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)

{

textbox1.Text = [the contents of the cell at column4 of the row that was
doubleclicked]

}

e.RowIndex contains the index of the row you double-clicked.
This should give you a start...

Markus
 
Edwin Smith said:
Hello:

I have a DataGridView control and I want to doubleclick a row and get a
single cell value.

Here's a snippet:

private void pATIENTSDataGridView_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)

{

textbox1.Text = [the contents of the cell at column4 of the row that
was doubleclicked]

}

This should be a simple task but I can't seem to get it.

Thanks

Edwin



textbox1.Text =
pATIENTSDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();

Regards,
Anne
 
AvdP said:
Edwin Smith said:
Hello:

I have a DataGridView control and I want to doubleclick a row and get a
single cell value.

Here's a snippet:

private void pATIENTSDataGridView_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)

{

textbox1.Text = [the contents of the cell at column4 of the row that
was doubleclicked]

}

This should be a simple task but I can't seem to get it.

Thanks

Edwin



textbox1.Text =
pATIENTSDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();

Regards,
Anne

Works great! Thanks.

I had already figured out the e.RowIndex and e.ColumnIndex values. I just
couldn't figure out how to use them to get the cell I wanted.

Edwin
 
Back
Top