// Returns the previous sibling element in the raw hierarchy. // Peripheral controls have always negative values. // Returns null is no previous internal override ProxySimple GetPreviousSibling(ProxySimple child) { GroupManager.GroupInfo groupInfo = GetGroupInfo(_hwnd, ID); if (groupInfo) { int [] items = groupInfo._items; int current = child._item; // The subset link has an index that is one past the list items // If we are on that then the previous is the last item in the items array. if (_isComctrlV6OnOsVerV6orHigher && current == groupInfo._count) { int index = items [groupInfo._count - 1]; return(CreateListViewItem(index)); } // find the index of the current lvitem int prevLocation = groupInfo.IndexOf(current) - 1; if (prevLocation <= -2) { throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); } if (prevLocation >= 0) { return(CreateListViewItem(items [prevLocation])); } } return(null); }
// retrieve lvitem column position in the Grid // To be called only when Group is enabled private int GetItemColumnPositionInGroup() { // get id of the group to which this item belongs int groupID = GetGroupID(_hwnd, _item); if (groupID != -1) { // get position of this lvitem within the array of all items in the group GroupManager.GroupInfo groupInfo = WindowsListViewGroup.GetGroupInfo(_hwnd, groupID); if (groupInfo) { int position = groupInfo.IndexOf(_item); //Array.IndexOf(groupInfo._items, _item); if (position != -1) { // number of columns in the grid int columnCount = WindowsListViewGroup.GetColumnCountExternal(_hwnd, groupID); // item's row position int itemRowPosition = position / columnCount; // item's column position return(position - (itemRowPosition * columnCount)); } } } return(-1); }
// Returns the next sibling element in the raw hierarchy. // Peripheral controls have always negative values. // Returns null if no next child internal override ProxySimple GetNextSibling(ProxySimple child) { GroupManager.GroupInfo groupInfo = GetGroupInfo(_hwnd, ID); if (groupInfo) { int [] items = groupInfo._items; int current = child._item; // find the index of the current lvitem int nextLocation = groupInfo.IndexOf(current) + 1; //Array.IndexOf(items, current) + 1; if (nextLocation <= 0) { // No more siblings return(null); } if (nextLocation < groupInfo._count) { return(CreateListViewItem(items [nextLocation])); } // List view groups in vista can have an extra link at the end that says // somthing like "show all 11 items..." if (_isComctrlV6OnOsVerV6orHigher && nextLocation == groupInfo._count) { NativeMethods.LVGROUP_V6 group = new NativeMethods.LVGROUP_V6(); group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6))); group.iGroupID = _groupID; group.mask = NativeMethods.LVGF_STATE; group.stateMask = NativeMethods.LVGS_SUBSETED; // Note: return code of GetGroupInfo() is not reliable. XSendMessage.GetGroupInfo(_hwnd, ref group); // ignore return code. // The items array holds the list items in this group. If we have a subset link we // don't store it with the list items because it isn't really a list item. Instead we just // create the subset link proxy with an item index one more than the last index. if ((group.state & NativeMethods.LVGS_SUBSETED) != 0) { return(CreateGroupSubsetLink(items [groupInfo._count - 1] + 1)); } } } return(null); }