Reputation: 2103
How can I iterate over a WPF DataGrid "as seen by the user" (e.g. the user might have sorted it or the user might have rearranged columns).
When I iterate using ItemsSource
foreach (System.Data.DataRowView dr in ResultDataGrid.ItemsSource)
{ .. }
then I am iterating over the original, unsorted DataGrid. Thank you for any help!
Upvotes: 0
Views: 135
Reputation: 7944
Ensure your underlying collection reflects the visual collection.
So instead of relying on the DataGrid
itself to do the sorting, for instance, sort the underlying ObservableCollection
so that when you iterate through it, you are iterating in visual order.
Upvotes: 1