Get the value of one cell from a DataGridView?

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
 
M

Markus Becker

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
 
A

AvdP

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
 
E

Edwin Smith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top