DataGrid "logical" row from HitTest
-
Guys, On the datagrid when you do a HitTest you get the "physical" row that the mouse is over. If the user has sorted the grid (by clicking on one of the column headers) and changed the order of the rows is there a way to get the "logical" row from the "physical" row? Thanks
-
Guys, On the datagrid when you do a HitTest you get the "physical" row that the mouse is over. If the user has sorted the grid (by clicking on one of the column headers) and changed the order of the rows is there a way to get the "logical" row from the "physical" row? Thanks
Get the
DataView
used to sort the data. If you bound yourDataGrid
to aDataView
, you're already done. If not, get theDataTable
you're binding to (whether it's theDataSource
or it's name is theDataMember
) and get theDefaultView
property.Microsoft MVP, Visual C# My Articles
-
Get the
DataView
used to sort the data. If you bound yourDataGrid
to aDataView
, you're already done. If not, get theDataTable
you're binding to (whether it's theDataSource
or it's name is theDataMember
) and get theDefaultView
property.Microsoft MVP, Visual C# My Articles
Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?
-
Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?
-
Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?
IIRC, you should be able to get it using
DataView[physicalRowIndex]
. This gets you aDataRowView
. Get theRow
property to get the actualDataRow
, though if you just want the value of a column in the row, you can get it as you would with aDataRow
using theDataRowView
.Microsoft MVP, Visual C# My Articles