public override OLVListItem GetPreviousItem(OLVListItem itemToFind)
{
if (!this.ShowGroups)
return base.GetPreviousItem(itemToFind);
// Sanity
if (this.OLVGroups == null || this.OLVGroups.Count == 0)
return null;
// If the given items is null, return the last member of the last group
if (itemToFind == null) {
OLVGroup lastGroup = this.OLVGroups[this.OLVGroups.Count - 1];
return this.GetItem(this.GroupingStrategy.GetGroupMember(lastGroup, lastGroup.VirtualItemCount - 1));
}
// 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 first member of the group, just return the previous member
if (indexWithinGroup > 0)
return this.GetItem(this.GroupingStrategy.GetGroupMember(this.OLVGroups[groupIndex], indexWithinGroup - 1));
// The item is the first member of its group. Return the last member of the previous group
// (if there is one)
if (groupIndex > 0) {
OLVGroup previousGroup = this.OLVGroups[groupIndex - 1];
return this.GetItem(this.GroupingStrategy.GetGroupMember(previousGroup, previousGroup.VirtualItemCount - 1));
}
return null;
}