My xamDataGrid is showing some data loaded through a DataTable set to the grid's DataSource property. The user then clicks some column headers to re-order the rows. At that point, how do I get the sorted record collection?
MyGrid.DataSource points to the original non-sorted list. I need the exact list that the xamDataGrid is showing.
Thanks. Your solution works.
Thumbs up for the good work.
Hello,
Thank you for your feedback. I have been looking into your question and you need to convert the Records into DataItems in order to get the underlying data.
For example, if your underlying objects are of type ‘Car’ you can use the following code :
List<Record> recs = this.xamDataGrid1.ViewableRecords.ToList();
List<Car> cars = new List<Car>();
foreach (var item in recs)
{
cars.Add((item as DataRecord).DataItem as Car);
}
If you need any further assistance on this matter, feel free to ask.
The ViewableRecords do hold the records in the sorted order. From this DataRecord list, how can I get to the fields values? How would I convert this DataRecord list to a DataView containing the original fields? I'm trying to use this sorted list as a DataSource for another component (a report actually).
Doing
report.DataSource = MyXamDataGrid.ViewableRecords.ToList();
isn't working because it's a list of DataRecords.
I have been looking into your question and you can use the following the ‘ViewableRecords’ property like e.g. :
List<Record> records = this.xamDataGrid1.ViewableRecords.ToList();