Retrieving data table index for datagrid index selected

D

Dvae c

I defined the source of a datagrid to a datatable. Because the
datagrid is actually bound to the default dataview, the data index
selected in the datagrid might not equal the actual datatable index
(i.e. if datagrid is sorted, filter applied).
Is there a way I can translate the datagrid selected index into the
proper datatable index value so as to get the correct data table row?
 
A

Alex Feinman [MVP]

VB.NET
Dim row as DataRow = CType(dataGrid.DataSource,
DataView)(dataGrid.CurrentRowIndex).Row
C#
DataRow row = (dataGrid.DataSource as
DataView)[dataGrid.CurrentRowIndex].Row as DataRow;
 
P

Paul W

I use HitTestInfo class of DataGrid to get the row selected, column
selected, or cell selected.
Here is an example of row selection
(I usually use OnMouseUp event)
Dim hti as DataGrid.HitTestInfo = myDataGrid.HitTest(e.X, e.Y)
Dim intRow as Integer
If hti.Type = DataGrid.HitTestType.Cell Then
intRow = hti.Row
End If

Hope this helps...
Paul
 

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