public virtual void BuildGroups(OLVColumn groupByColumn, SortOrder groupByOrder,
OLVColumn column, SortOrder order, OLVColumn secondaryColumn, SortOrder secondaryOrder)
{
// Sanity checks
if (groupByColumn == null)
return;
// Getting the Count forces any internal cache of the ListView to be flushed. Without
// this, iterating over the Items will not work correctly if the ListView handle
// has not yet been created.
#pragma warning disable 168
int dummy = this.Items.Count;
#pragma warning restore 168
// Collect all the information that governs the creation of groups
GroupingParameters parms = this.CollectGroupingParameters(groupByColumn, groupByOrder,
column, order, secondaryColumn, secondaryOrder);
// Trigger an event to let the world create groups if they want
CreateGroupsEventArgs args = new CreateGroupsEventArgs(parms);
if (parms.GroupByColumn != null)
args.Canceled = !parms.GroupByColumn.Groupable;
this.OnBeforeCreatingGroups(args);
if (args.Canceled)
return;
// If the event didn't create them for us, use our default strategy
if (args.Groups == null)
args.Groups = this.MakeGroups(parms);
// Give the world a chance to munge the groups before they are created
this.OnAboutToCreateGroups(args);
if (args.Canceled)
return;
// Create the groups now
this.OLVGroups = args.Groups;
this.CreateGroups(args.Groups);
// Tell the world that new groups have been created
this.OnAfterCreatingGroups(args);
}