Pick DataGrid column value

  • Thread starter Thread starter RP
  • Start date Start date
I want to pick a column value as the user selects a row of the
DataGrid.

Depending on the DataSource you should be able to get this information using DataGrid.CurrentCell/CurrentRowIndex.

If you use a DataGridView, you can also use DataGridView.CurrentRow.Cells[columnindex]

You can also get this information using DataBinding
 
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.
 
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.


Depending on the DataSource you should be able to get this information using DataGrid.CurrentCell/CurrentRowIndex.

If you use a DataGridView, you can also use DataGridView.CurrentRow.Cells[columnindex]

You can also get this information using DataBinding

Well, using a DataGrid I think you need to look up the values from the DataSource. If you can, use DataGridView instead.
 
RP said:
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.

You can use the Cells collection in the CurrentRow object for this. It's
probably better to get the actual DataSource information but if you
absolutely have to have what's in the grid this is the way to do it:

someVar = yourDataGridView.CurrentRow.Cells["someColumn"].Value;


There may be other/better ways to retrieve a particular column in the
currently selected Row, but I've used the above method in several places.


Chris.
 
Chris said:
RP said:
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.

You can use the Cells collection in the CurrentRow object for this. It's
probably better to get the actual DataSource information but if you
absolutely have to have what's in the grid this is the way to do it:

someVar = yourDataGridView.CurrentRow.Cells["someColumn"].Value;


There may be other/better ways to retrieve a particular column in the
currently selected Row, but I've used the above method in several places.

*Smacks self with the read-entire-thread-before-replying stick*

Chris.
 

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

Back
Top