BrightIdeasSoftware.FilterMenuBuilder.HandleSelectAllItem C# (CSharp) Метод

HandleSelectAllItem() защищенный Метод

Handle any checking/unchecking of the Select All option, and keep its checkedness in sync with everything else that is checked.
protected HandleSelectAllItem ( System.Windows.Forms.ItemCheckEventArgs e, BrightIdeasSoftware.ToolStripCheckedListBox checkedList, int selectAllIndex ) : void
e System.Windows.Forms.ItemCheckEventArgs
checkedList BrightIdeasSoftware.ToolStripCheckedListBox
selectAllIndex int
Результат void
        protected virtual void HandleSelectAllItem(ItemCheckEventArgs e, ToolStripCheckedListBox checkedList, int selectAllIndex)
        {
            // Did they check/uncheck the "Select All"?
            if (e.Index == selectAllIndex) {
                if (e.NewValue == CheckState.Checked)
                    checkedList.CheckAll();
                if (e.NewValue == CheckState.Unchecked)
                    checkedList.UncheckAll();
                return;
            }

            // OK. The user didn't check/uncheck SelectAll. Now we have to update it's
            // checkedness to reflect the state of everything else
            // If all clusters are checked, we check the Select All.
            // If no clusters are checked, the uncheck the Select All.
            // For everything else, Select All is set to indeterminate.

            // How many items are currenty checked?
            int count = checkedList.CheckedItems.Count;

            // First complication.
            // The value of the Select All itself doesn't count
            if (checkedList.GetItemCheckState(selectAllIndex) != CheckState.Unchecked)
                count -= 1;

            // Another complication.
            // CheckedItems does not yet know about the item the user has just
            // clicked, so we have to adjust the count of checked items to what
            // it is going to be
            if (e.NewValue != e.CurrentValue) {
                if (e.NewValue == CheckState.Checked)
                    count += 1;
                else
                    count -= 1;
            }

            // Update the state of the Select All item
            if (count == 0)
                checkedList.SetItemState(selectAllIndex, CheckState.Unchecked);
            else if (count == checkedList.Items.Count - 1)
                checkedList.SetItemState(selectAllIndex, CheckState.Checked);
            else
                checkedList.SetItemState(selectAllIndex, CheckState.Indeterminate);
        }