Example #1
0
        private void SelectiveSelection(int iIndex)
        {
            // This is a special case and will be used when the user clicks on an item
            // while the control key is pressed or presses the space bar button while an
            // item has the focus.

            // unfocus the previously focused item
            if (focusedIndex >= 0 && focusedIndex < items.Count)
                items[focusedIndex].Focused = false;

            ContainerListViewItem item = items[iIndex];

            if (items[iIndex].Selected)  // Already selected? De-select.
            {
                items[iIndex].Focused = false;
                items[iIndex].Selected = false;

                int i = selectedItems[item];
                selectedIndices.Remove(i);
                selectedItems.Remove(item);

                if (this.focusedItem == item) focusedItem = null;

                MakeSelectedVisible();

                OnSelectedIndexChanged(new EventArgs());
            }
            else
            {
                item.Focused = true;
                item.Selected = true;

                selectedIndices.Add(iIndex);
                selectedItems.Add(item);
                this.focusedItem = item;

                MakeSelectedVisible();

                OnSelectedIndexChanged(new EventArgs());
            }

            Invalidate();
        }
Example #2
0
        private void MoveToIndex(int iIndex)
        {
            if ((iIndex < -1) | (iIndex >= this.items.Count)) return;

            if (iIndex == focusedIndex) return; /// Might occur on End on first item or
                                                ///             on Home on the first item or
                                                ///             if the user clicks on the current node

            UnselectAll();

            this.selectedItems.Clear();
            this.selectedIndices.Clear();

            if (focusedItem != null)
            {
                focusedItem.Selected = false;
                focusedItem.Focused = false;
            }

            focusedIndex = iIndex;

            if ((this.multiSelectMode == MultiSelectMode.Single) | (firstSelected == -1))
            {
                firstSelected = focusedIndex;
                items[focusedIndex].Focused = true;
                focusedItem = items[focusedIndex];
            }

            ShowSelectedItems();

            MakeSelectedVisible();
            OnSelectedIndexChanged(new EventArgs());

            Invalidate(this.ClientRectangle);
        }