Ejemplo n.º 1
0
        /// <summary>
        /// Handle a user-generated ItemCheck event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        virtual protected void HandleItemChecked(object sender, ItemCheckEventArgs e)
        {
            ToolStripCheckedListBox checkedList = sender as ToolStripCheckedListBox;

            if (checkedList == null)
            {
                return;
            }
            OLVColumn column = checkedList.Tag as OLVColumn;

            if (column == null)
            {
                return;
            }
            ObjectListView listView = column.ListView as ObjectListView;

            if (listView == null)
            {
                return;
            }

            // Deal with the "Select All" item if there is one
            int selectAllIndex = checkedList.Items.IndexOf(SELECT_ALL_LABEL);

            if (selectAllIndex >= 0)
            {
                HandleSelectAllItem(e, checkedList, selectAllIndex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Do the work of making a menu that shows the clusters to the users
        /// </summary>
        /// <param name="column"></param>
        /// <param name="clusters"></param>
        /// <returns></returns>
        virtual protected ToolStripMenuItem CreateFilteringMenuItem(OLVColumn column, List <ICluster> clusters)
        {
            ToolStripCheckedListBox checkedList = new ToolStripCheckedListBox();

            checkedList.Tag = column;
            foreach (ICluster cluster in clusters)
            {
                checkedList.AddItem(cluster, column.ValuesChosenForFiltering.Contains(cluster.ClusterKey));
            }
            if (!String.IsNullOrEmpty(SELECT_ALL_LABEL))
            {
                int checkedCount = checkedList.CheckedItems.Count;
                if (checkedCount == 0)
                {
                    checkedList.AddItem(SELECT_ALL_LABEL, CheckState.Unchecked);
                }
                else
                {
                    checkedList.AddItem(SELECT_ALL_LABEL, checkedCount == clusters.Count ? CheckState.Checked : CheckState.Indeterminate);
                }
            }
            checkedList.ItemCheck += new ItemCheckEventHandler(HandleItemCheckedWrapped);

            ToolStripMenuItem clearAll = new ToolStripMenuItem(CLEAR_ALL_FILTERS_LABEL, ClearFilteringImage, delegate(object sender, EventArgs args) {
                this.ClearAllFilters(column);
            });
            ToolStripMenuItem apply = new ToolStripMenuItem(APPLY_LABEL, FilteringImage, delegate(object sender, EventArgs args) {
                this.EnactFilter(checkedList, column);
            });
            ToolStripMenuItem subMenu = new ToolStripMenuItem(FILTERING_LABEL, null, new ToolStripItem[] {
                clearAll, new ToolStripSeparator(), checkedList, apply
            });

            return(subMenu);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Apply the selected values from the given list as a filter on the given column
        /// </summary>
        /// <param name="checkedList">A list in which the checked items should be used as filters</param>
        /// <param name="column">The column for which a filter should be generated</param>
        virtual protected void EnactFilter(ToolStripCheckedListBox checkedList, OLVColumn column)
        {
            ObjectListView olv = column.ListView as ObjectListView;

            if (olv == null || olv.IsDisposed)
            {
                return;
            }

            // Collect all the checked values
            ArrayList chosenValues = new ArrayList();

            foreach (object x in checkedList.CheckedItems)
            {
                ICluster cluster = x as ICluster;
                if (cluster != null)
                {
                    chosenValues.Add(cluster.ClusterKey);
                }
            }
            column.ValuesChosenForFiltering = chosenValues;

            olv.UpdateColumnFiltering();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle any checking/unchecking of the Select All option, and keep
        /// its checkedness in sync with everything else that is checked.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="checkedList"></param>
        /// <param name="selectAllIndex"></param>
        virtual protected 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);
            }
        }