protected override void OnDropDownItemClicked(ToolStripItemClickedEventArgs e) { base.OnDropDownItemClicked(e); var menuItem = (ToolStripMenuItem)e.ClickedItem; //we do not allow unchecking by clicking an already checked item if (menuItem.Checked) { return; } switch (DropDownItems.IndexOf(menuItem)) { case 0: dateFilterDialog.Set24Hours(); break; case 1: dateFilterDialog.SetDays(DateFilterDialog.DaysInPastOptions.THREE_DAYS); break; case 2: dateFilterDialog.SetDays(DateFilterDialog.DaysInPastOptions.SEVEN_DAYS); break; case 3: dateFilterDialog.SetDays(DateFilterDialog.DaysInPastOptions.THIRTY_DAYS); break; case 4: DialogResult result = dateFilterDialog.ShowDialog(); if (result != DialogResult.OK) { return; } break; case 6: dateFilterDialog.SetNone(); break; } foreach (ToolStripItem t in DropDownItems) { var mt = t as ToolStripMenuItem; if (mt != null) { mt.Checked = false; } } menuItem.Checked = true; if (FilterChanged != null) { FilterChanged(); } }
private void InsertItemsAfterItem(ToolStripItem anchorItem, CopyToClipboardToolStripMenuItem[] items) { var startIndex = DropDownItems.IndexOf(anchorItem) + 1; for (var i = 0; i < items.Length; ++i) { DropDownItems.Insert(startIndex + i, items[i]); } }