namespace WinFormsLibrary { public partial class DropDownList : UserControl { public DropDownList() { InitializeComponent(); } public void Clear() { comboBox.Items.Clear(); } public void LoadValues(List values) { if (values.Count == 0) { return; } comboBox.Items.AddRange(values.ToArray()); } public string Selected { get { if(comboBox.Items.Count == 0) { return ""; } if(comboBox.SelectedItem == null) { return ""; } return comboBox.SelectedItem.ToString()!; } set { if (comboBox.Items.Contains(value)) { comboBox.SelectedItem = value; } } } public ComboBox.ObjectCollection comboBoxItems { get { return comboBox.Items; } } private EventHandler _onValueChanged; public event EventHandler ValueChanged { add { _onValueChanged += value; } remove { _onValueChanged -= value; } } private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { _onValueChanged?.Invoke(sender, e); } } }