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 BulatovaComponents.Components { public partial class ComboBoxControl : UserControl { public ComboBoxControl() { InitializeComponent(); } public string SelectedValue { get { return comboBoxCustom.SelectedItem != null ? comboBoxCustom.SelectedItem.ToString() : ""; } set { if (comboBoxCustom.Items.Contains(value)) //если есть такой элемент, то помечаем, если нет, ничего не делаем { comboBoxCustom.SelectedItem = value; } } } public event Action SelectedValueChange; public void addItems(List items) { foreach (string item in items) { comboBoxCustom.Items.Add(item); } } public void clear() { comboBoxCustom.Items.Clear(); } private void comboBoxCustom_SelectedIndexChanged(object sender, EventArgs e) { SelectedValueChange?.Invoke(comboBoxCustom.SelectedItem.ToString()); } } }