Exemple #1
0
        private void FilterMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripCheckBoxMenuItem menuItem = (ToolStripCheckBoxMenuItem)sender;

            IEnumerable <ListViewItem> items = null;

            foreach (var filterOption in _filterMenus)
            {
                var selectedFiltersForThisColumn = filterOption.Value.Items.Cast <ToolStripCheckBoxMenuItem>().Where(item => item.Checked).Select(item => item.Tag).ToArray();

                if (selectedFiltersForThisColumn.Length == 0)
                {
                    //this.Columns[fitlerOption.Key].ImageIndex = -1;
                    //SetImageOnColumnHeader(filterOption.Key, false);
                    //UpdateColumnImage(filterOption.Key, false);

                    continue;
                }

                //this.Columns[fitlerOption.Key].ImageIndex = 0;
                //SetImageOnColumnHeader(filterOption.Key, true);
                //UpdateColumnImage(filterOption.Key, true);

                if (items == null)
                {
                    items = _originalItems.Where(item => Array.IndexOf(selectedFiltersForThisColumn, item.SubItems[filterOption.Key].Text) >= 0);
                }
                else
                {
                    items = items.Where(item => Array.IndexOf(selectedFiltersForThisColumn, item.SubItems[filterOption.Key].Text) >= 0);
                }
            }

            this.SuspendLayout();

            try
            {
                this.Items.Clear();
                this.Items.AddRange((items == null) ? _originalItems.ToArray() : items.ToArray());
            }
            finally
            {
                this.ResumeLayout();
            }
        }
Exemple #2
0
        private void BuildFilterMenu()
        {
            foreach (int columnIndex in _filterMenus.Keys.ToList())
            {
                ContextMenuStrip filterMenu = new ContextMenuStrip();

                var distinctValues = _originalItems
                                     .Select(item => item.SubItems[columnIndex].Text)
                                     .Distinct();

                foreach (var item in distinctValues)
                {
                    ToolStripCheckBoxMenuItem newItem = new ToolStripCheckBoxMenuItem(String.IsNullOrEmpty(item) ? "(blank)" : item);
                    newItem.Tag    = item;
                    newItem.Click += FilterMenuItem_Click;
                    filterMenu.Items.Add(newItem);
                }

                filterMenu.Closing += FitlerMenu_Closing;

                _filterMenus[columnIndex] = filterMenu;
            }
        }