using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Controls { public partial class CustomComboBox : UserControl { /// /// Конструктор /// public CustomComboBox() { InitializeComponent(); } /// /// Очищение списка /// public void ComboBoxClear() { comboBoxMain.Items.Clear(); } /// /// Выбранный элемент /// public string SelectedItem { get { if (comboBoxMain.Items.Count == 0) { return ""; } if (comboBoxMain.SelectedItem == null) { return ""; } return comboBoxMain.SelectedItem.ToString()!; } set { if (comboBoxMain.Items.Contains(value)) { comboBoxMain.SelectedItem = value; } } } /// /// Публичное свойство /// public ComboBox.ObjectCollection ComboBoxItems { get { return comboBoxMain.Items; } } /// /// Событие, вызываемое при смене значения /// private EventHandler _onValueChangedEvent; /// /// Событие, вызываемое при смене значения /// public event EventHandler ValueChanged { add { _onValueChangedEvent += value; } remove { _onValueChangedEvent -= value; } } /// /// Смена значения /// private void CustomComboBox_SelectedValueChanged(object sender, EventArgs e) { _onValueChangedEvent?.Invoke(sender, e); } } }