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; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header; namespace FormLibrary { public partial class CustomListBox : UserControl { public event EventHandler? SelectedItemChanged; public CustomListBox() { InitializeComponent(); } public string SelectedItem { get => listBox1.SelectedItem?.ToString() ?? string.Empty; set => listBox1.SelectedIndex = listBox1.Items.IndexOf(value); } private void ListBox1_SelectedIndexChanged(object? sender, EventArgs e) { SelectedItemChanged?.Invoke(this, EventArgs.Empty); } public void PopulateListBox(List items) { listBox1.Items.Clear(); foreach (var item in items) { listBox1.Items.Add(item); } } public void ClearListBox() { listBox1.Items.Clear(); } } }