Im having an issue with the XamDataGrid.
I want to get the row the user has clicked.
I have a collection lets call it MyCollection, and im using the following to retrieve the selected row from said collection..
MyCollection[invoiceListGrid.xamDataGrid.ActiveRecord.Index]
my issue occurrs when the grid has been sorted using the column headers, i.e. sort by ID or something.
In this case i would expect that (for example) clicking the 5th record would maybe give me an index of 49 (because its number 49 in the underlying collection) and I would get a VisibleIndex of 5 (because thats where it is in the visible list.
However, I actually get 5 for both properties. I therefore cant see a way of obtaining the selected row.
I have also tried the SelectedRecordCollection but this only works if you select the row with the rowselector thing at the left hand side.
If i have misunderstood the use of these properties or have missed something else please let me know.
Hi,
Both Index and VisibleIndex correspond to the order in which they are in the data grid's record collection. For the index that you can use to index into the underlying data list, use the DataRecord's DataItemIndex instead or the DataItem property itself if all that you are interested in getting the underlying data object in the list. Something like this:
DataRecord dataRecord = _dp.ActiveRecord as DataRecord;if ( null != dataRecord ){ object dataItem; dataItem = MyCollection[dataRecord.DataItemIndex]; // Alternatively you can simply access the DataItem property. dataItem = dataRecord.DataItem;}
Hope this helps,
Sandip