public override OLVListItem GetNextItem(OLVListItem itemToFind)
{
if (!this.ShowGroups)
return base.GetNextItem(itemToFind);
// Sanity
if (this.OLVGroups == null || this.OLVGroups.Count == 0)
return null;
// If the given item is null, return the first member of the first group
if (itemToFind == null) {
return this.GetItem(this.GroupingStrategy.GetGroupMember(this.OLVGroups[0], 0));
}
// Find where this item occurs (which group and where in that group)
int groupIndex = this.GroupingStrategy.GetGroup(itemToFind.Index);
int indexWithinGroup = this.GroupingStrategy.GetIndexWithinGroup(this.OLVGroups[groupIndex], itemToFind.Index);
// If it's not the last member, just return the next member
if (indexWithinGroup < this.OLVGroups[groupIndex].VirtualItemCount - 1)
return this.GetItem(this.GroupingStrategy.GetGroupMember(this.OLVGroups[groupIndex], indexWithinGroup + 1));
// The item is the last member of its group. Return the first member of the next group
// (unless there isn't a next group)
if (groupIndex < this.OLVGroups.Count - 1)
return this.GetItem(this.GroupingStrategy.GetGroupMember(this.OLVGroups[groupIndex + 1], 0));
return null;
}