2024-12-16 11:28:31 +04:00

42 lines
863 B
C#

namespace Library36
{
public partial class CustomListBox : UserControl
{
private ListBox listBox;
public event EventHandler ValueChanged;
public CustomListBox()
{
InitializeComponent();
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
ValueChanged?.Invoke(this, EventArgs.Empty);
}
public string SelectedValue
{
get => listBoxCustom.SelectedItem?.ToString() ?? string.Empty;
set
{
if (listBoxCustom.Items.Contains(value))
listBoxCustom.SelectedItem = value;
}
}
public ListBox.ObjectCollection ItemCollection
{
get => listBoxCustom.Items;
}
public void ClearList()
{
listBoxCustom.Items.Clear();
}
public void PopulateList(List<string> items)
{
listBoxCustom.Items.Clear();
foreach (var item in items)
{
listBoxCustom.Items.Add(item);
}
}
}
}