Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
XamDataGrid Set selected row by Identity
posted

Hey,

I have a XamDataGrid, that displays a SQL-Table via a DataTable. 
Multiple users work on this table, so each of them can insert new rows.

Because of that I need to update my DataTable after each RecordUpdate.
The problem is, that after the DataTable is refilled, the selection from before isn't selected anymore.

I cant select a row by the index, cause it can happen another user added a row, so the index of the row is not the same anymore.

IS there a way to select a row by the Identity in the ID-Column? Or any other way to select a row beside of the index.

Parents
  • 33490
    Offline posted

    Hello Benedikt,

    I have been investigating into your requirement in this case, and you have mentioned the DataTable being refilled, which I assume means that you are adding all new DataRow instances. If so, the behavior you are seeing is expected, as the XamDataGrid will generate new DataRecord elements for the new underlying data items in your table.

    Assuming my impression of the above is correct, the best thing I can recommend in this case is to have a unique identifier or data column value for your DataRows that you can use. Each DataRecord element in the XamDataGrid.Records collection has a DataItem property that will return the underlying data item that the record represents. Assuming that this unique identifier would not change, you could get the underlying data items for your selected records, get the data items associated with them, and use the unique identifier to reselect the representative records after the change.

    The code that you could use for this would involve utilization of the XamDataGrid.SelectedItems.Records collection, as this will contain all of the selected DataRecords in your grid. You could get a collection of the DataItem elements for each of those DataRecords with respect to the unique identifier, and then after making the change to your DataTable, loop through the XamDataGrid.Records collection searching for a DataItem that matches that unique identifier and set the DataRecord.IsSelected property to "true" for those items.

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.

Reply Children