Hi,
how can I get the Row-Object from the underlying data object?
In my case, I have to select a specific row but I don't have the associated row object.
Thank you,
Stefan
Hello Stefan,
Thank you for your feedback.I am glad I could help you achieve the functionality you are looking for.
This example's purpose was to demonstrate adding Rows to the SelectedRows Collection and also a filtering example.Its implementation depends solely on your scenario and requirements.
Thank you very much!
This is exactly what I need.
But why are you comparing Id and Name instead of object references (r.Data == Data[customDataIndex])? If I'm correct, they must be equal.
Regards
Thank you for your detailed description.
Following it I have created a small sample application. Please try and test it whether this is close to your scenario.
In it I have added a button which uses the second item from the data collection to match the corresponding row and after that to add it to the SelectedRows Collection.
Please note that if you filter out the second row, from the XamGrid it will no longer be available (if you try and debug) and thus it will no longer can be selected.
Thank you for your answer,
but I need to explain my problem a little bit more:At first, I forgot to say, that I need to do this by code (MVVM project).
So, I want to add a specific row to the SelectedRowsCollection, that this row becomes selected.But I only have the data-object that is bound to a row through the ItemsSource property.Therefor, I need a way to find the row, that represents this object (Not visually).
XamGrid uses Virtualization. If you have the data collection and the XamGrid's row collection, all shown on the screen, you can search for a specific row. If you use Paging or Filtering is different scenario - not all the rows will be available, so if you want to select a row it might not be visible and you will get NullReferenceException.
In your scenario I will suggest get the rows of the XamGrid, that it currently has, look for the one you want to select and select it only if it is available.
If you have additional questions concerning this matter, please let me know.