private static void HandleSelectAll(ItemCheckEventArgs e, ToolStripCheckedListBox checkedList, int selectAllIndex) { if (e.Index == selectAllIndex) { if (e.NewValue == CheckState.Checked) { checkedList.CheckAll(); } if (e.NewValue == CheckState.Unchecked) { checkedList.UncheckAll(); } return; } var count = checkedList.CheckedItems.Count; if (checkedList.GetItemCheckState(selectAllIndex) != CheckState.Unchecked) { count--; } if (e.NewValue != e.CurrentValue) { if (e.NewValue == CheckState.Checked) { count++; } else { count--; } } 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); } }
private ToolStripMenuItem CreateColumnFilteringMenuItem(OLVColumn column, List <ICluster> clusters) { var listBox = new ToolStripCheckedListBox { Tag = column, }; foreach (var cluster in clusters) { listBox.AddItem(cluster, column.ValuesChosenForFiltering.Contains(cluster.ClusterKey)); } var state = listBox.CheckedItems.Count == 0 ? CheckState.Unchecked : listBox.CheckedItems.Count == clusters.Count ? CheckState.Checked : CheckState.Indeterminate; listBox.AddItem(SELECT_ALL_LABEL, state); listBox.ItemCheck += HandleItemCheckedWrapped; var clearAllMenuItem = new ToolStripMenuItem(CLEAR_ALL_FILTERS_LABEL, ClearFilteringImage, (sender, args) => ClearAllFilters(column)); var applMenuItem = new ToolStripMenuItem(APPLY_LABEL, FilteringImage, (sender, args) => ApplyFilter(listBox, column)); var freeText = new ToolStripTextBoxWithPlaceHolderText() { Tag = column, Text = "", PlaceHolderText = "search in column", }; var menuItem = new ToolStripMenuItem(FILTERING_LABEL, null, new ToolStripItem[] { freeText, new ToolStripSeparator(), clearAllMenuItem, new ToolStripSeparator(), listBox, applMenuItem }); return(menuItem); }
private void ApplyFilter(ToolStripCheckedListBox checkedList, OLVColumn column) { if (!(column.ListView is ObjectListView olv) || olv.IsDisposed) { return; } var textBox = (checkedList.GetCurrentParent() as ToolStripDropDownMenu).Items[0] as ToolStripTextBox; if (!string.IsNullOrWhiteSpace(textBox.Text)) { var filter = TextMatchFilter.Contains(olv, textBox.Text); filter.Columns = new[] { column }; column.ValueBasedFilter = filter; column.ValuesChosenForFiltering = new ArrayList(); olv.UpdateColumnFiltering(); } else { base.EnactFilter(checkedList, column); } }