void cb_SelectionChangeCommitted(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; ComboBoxItemToggle item = cb.SelectedItem as ComboBoxItemToggle; if (item != null) { if (!item.Enabled) { cb.SelectedIndex = LastSelection; } } }
public void ConfigureModFilter() { _cbModFilter.DropDown += modFilter_DropDown; modFilter_DropDown(null, null); if (_cbModFilter.Items.Count == 0) { _setStatus(GlobalSettings.Language.GetTag("iatag_stash_not_found")); Logger.Warn("Could not locate any stash files"); } else { foreach (var elem in _cbModFilter.Items) { ComboBoxItemToggle item = elem as ComboBoxItemToggle; if (item != null && item.Enabled) { _cbModFilter.SelectedItem = item; break; } } } }
private void comboBox_DrawItem(object sender, DrawItemEventArgs e) { ComboBox comboBox = (ComboBox)sender; if (e.Index >= 0) { ComboBoxItemToggle item = comboBox.Items[e.Index] as ComboBoxItemToggle; if (!item.Enabled) { e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); e.Graphics.DrawString(comboBox.Items[e.Index].ToString(), comboBox.Font, Brushes.LightSlateGray, e.Bounds); } else { e.DrawBackground(); // Set the brush according to whether the item is selected or not Brush br = ((e.State & DrawItemState.Selected) > 0) ? SystemBrushes.HighlightText : SystemBrushes.ControlText; e.Graphics.DrawString(comboBox.Items[e.Index].ToString(), comboBox.Font, br, e.Bounds); e.DrawFocusRectangle(); } } }