/// <summary> /// Return the position of the given itemIndex in the list as it currently shown to the user. /// If the control is not grouped, the display order is the same as the /// sorted list order. But if the list is grouped, the display order is different. /// </summary> /// <param name="itemIndex"></param> /// <returns></returns> public virtual int GetItemIndexInDisplayOrder(int itemIndex) { if (!ShowGroups) { return(itemIndex); } int groupIndex = GroupingStrategy.GetGroup(itemIndex); int displayIndex = 0; for (int i = 0; i < groupIndex - 1; i++) { displayIndex += OLVGroups[i].VirtualItemCount; } displayIndex += GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemIndex); return(displayIndex); }
/// <summary> /// Return the ListViewItem that appears immediately before the given item. /// If the given item is null, the last item in the list will be returned. /// Return null if the given item is the first item. /// </summary> /// <param name="itemToFind">The item that is before the item that is returned</param> /// <returns>A ListViewItem</returns> public override OLVListItem GetPreviousItem(OLVListItem itemToFind) { if (!ShowGroups) { return(base.GetPreviousItem(itemToFind)); } // Sanity if (OLVGroups == null || OLVGroups.Count == 0) { return(null); } // If the given items is null, return the last member of the last group if (itemToFind == null) { OLVGroup lastGroup = OLVGroups[OLVGroups.Count - 1]; return(GetItem(GroupingStrategy.GetGroupMember(lastGroup, lastGroup.VirtualItemCount - 1))); } // Find where this item occurs (which group and where in that group) int groupIndex = GroupingStrategy.GetGroup(itemToFind.Index); int indexWithinGroup = GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemToFind.Index); // If it's not the first member of the group, just return the previous member if (indexWithinGroup > 0) { return(GetItem(GroupingStrategy.GetGroupMember(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 = OLVGroups[groupIndex - 1]; return(GetItem(GroupingStrategy.GetGroupMember(previousGroup, previousGroup.VirtualItemCount - 1))); } return(null); }
/// <summary> /// Return the ListViewItem that appears immediately after the given item. /// If the given item is null, the first item in the list will be returned. /// Return null if the given item is the last item. /// </summary> /// <param name="itemToFind">The item that is before the item that is returned, or null</param> /// <returns>A OLVListItem</returns> public override OLVListItem GetNextItem(OLVListItem itemToFind) { if (!ShowGroups) { return(base.GetNextItem(itemToFind)); } // Sanity if (OLVGroups == null || OLVGroups.Count == 0) { return(null); } // If the given item is null, return the first member of the first group if (itemToFind == null) { return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[0], 0))); } // Find where this item occurs (which group and where in that group) int groupIndex = GroupingStrategy.GetGroup(itemToFind.Index); int indexWithinGroup = GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemToFind.Index); // If it's not the last member, just return the next member if (indexWithinGroup < OLVGroups[groupIndex].VirtualItemCount - 1) { return(GetItem(GroupingStrategy.GetGroupMember(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 < OLVGroups.Count - 1) { return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[groupIndex + 1], 0))); } return(null); }