Hi.
We're using the XamDataGrid and are trying to programmatically group the grid by a column, directly followed by expanding/collapsing certain groups. We use the following code to perform the grouping:
We then loop through the xamDataGrid.Records (which should all now be of type GroupByRecord), and mark them as either expanded or not. Both actions (the grouping and expansion/collapsing) work, but not both at the same time. The problem with the expansion/collapsing is that the records have not yet become GroupByRecords.
It seems like the sorting/grouping occurs asynchronously and we have not been able to find an event that fires when the sorting/grouping finishes. (There's a Grouped event and such, but that only fires when the grouping is triggered by the end user).
Any help is appreciated!
Lars Andreas
Hello Lars,
I have reproduced locally that situation and everything works fine with me or at least what I think you are asking.
I have created a table and group records programatically like you have done. The loop through all of them and expand and collapse them. I am not sure what is the problem so I will paste you my source code. I am also using NetAdvantage for WPF 2008 Vol. 2.
<igDP:XamDataGrid Name="xamDataGrid1"> </igDP:XamDataGrid> <Button Height="30" Name="button1" Width="64" Click="button1_Click">Group</Button> <Button Height="30" Name="button2" Width="64" Click="button2_Click">Expand</Button> <Button Height="30" Name="button3" Width="64"Click="button3_Click">Collapse</Button>
and the Code-Behind file:
public class Numbers { public int A { get; set; } public int B { get; set; } public int C { get; set; } public Numbers(int a, int b, int c) { A = a; B = b; C = c; } } ObservableCollection<Numbers> collection = new ObservableCollection<Numbers>(); public Window1() { InitializeComponent(); collection.Add(new Numbers(1, 2, 3)); collection.Add(new Numbers(5, 6, 7)); collection.Add(new Numbers(2, 3, 4)); collection.Add(new Numbers(7, 8, 9)); collection.Add(new Numbers(2, 2, 1)); collection.Add(new Numbers(5, 5, 9)); xamDataGrid1.DataSource = collection; } private void button1_Click(object sender, RoutedEventArgs e) { xamDataGrid1.FieldLayouts[0].SortedFields.Clear(); xamDataGrid1.FieldLayouts[0].SortedFields.Add(new FieldSortDescription { FieldName = "A", IsGroupBy = true }); xamDataGrid1.FieldLayouts[0].SortedFields.Add(new FieldSortDescription { FieldName = "B", IsGroupBy = true }); } private void button2_Click(object sender, RoutedEventArgs e) { foreach (var r in xamDataGrid1.Records) { r.IsExpanded = true; } } private void button3_Click(object sender, RoutedEventArgs e) { foreach (var r in xamDataGrid1.Records) { r.IsExpanded = false; } } }
I hope this helps.
Hi, and thanks for your reply!
Our problem is somewhat different. We perform the grouping and expanding in the same method (as the result of a single user action). We took your example code and copied the code from button2_Click into button1_Click:
Clicking button1 for the first time will only group the data, but not expand the groups. If you press the button once more (while the data is grouped, but not expanded) the groups will expand.