namespace CustomComponents { public partial class DropDownList : UserControl { public DropDownList() { InitializeComponent(); } public void AddingToList(string Value) { if (Value == null) { return; } comboBox.Items.Add(Value); } public void Clear() { comboBox.Items.Clear(); } 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; } } } private EventHandler _explicitEvent; public event EventHandler ExplicitEvent { add { _explicitEvent += value; } remove { _explicitEvent -= value; } } private void comboBox_SelectedValueChanged(object sender, EventArgs e) { _explicitEvent?.Invoke(sender, e); } } }