I have managed to group my datagrid using the below found elsewhere on this site.
Problem: How to expand an item in the group by text value after the items have been grouped?
Issues: There is not such event as AfterGrouping and the myGrid.Grouped event does not fire if you group things programmatically.
"
Field fld = this.AreaUnitDetails.FieldLayouts[0].Fields[4]; // Type FieldSortDescription fsd = new FieldSortDescription(); fsd.Field = fld; fsd.Direction = ListSortDirection.Ascending; fsd.IsGroupBy = true; this.AreaUnitDetails.FieldLayouts[0].SortedFields.Add(fsd); " // Check the groups bool gbsf = this.AreaUnitDetails.FieldLayouts[0].HasGroupBySortFields; var temp = this.AreaUnitDetails.Records.DataPresenter.GetRecordsInView(true);
Ok, so the problem begins....
1. This code must return for the grid to actually become grouped.
2. How do I expand one of the grouped items after the collection has been grouped?
3. There is no such event as after grouping so there is nothing to act on.
4. I am performing this from the Display CTs button.
Attached is a view of my grouped collection. I want to expand the "CT" items by the same label after the records have been grouped - without user interaction.
Thanks,
Glenn Long
Hello Glenn,
You are right, there is no specific event with name like "AfterGrouping", but you can use couple of other events.
You can use the InitializeRecord event. This will fire, because records will be reinitalized and become GroupByRecords, so you can check if the record is GroupByRecord and set IsExpanded=true is needed.
You can also use RecordsInViewChanged event, which will also fire. Again, you can get the records by GetRecordsInView method and see if they are groupbyrecords and expand the one you need.
Let me know if you have questions on this.
All, Thanks for the tips. You are both mostly right. The only caveat I found was that trying to use InitializeRecord did not fire from code behind after the grid was initially loaded. That only worked when clicking the +- expander.
Good news, the below works great and fires at the appropriate time (after grouping is complete). One caveat is that it fires at anytime there is a change in the current view of the grid.
void AreaUnitDetails_RecordsInViewChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordsInViewChangedEventArgs e) { Console.WriteLine(e.Source.ToString()); Infragistics.Windows.DataPresenter.Record[] gbr; gbr = this.AreaUnitDetails.GetRecordsInView(false); foreach (Infragistics.Windows.DataPresenter.Record rec in gbr) { if (!rec.IsExpanded && rec.Description.StartsWith("CT")) rec.IsExpanded = true; } }