PIbd-31_Rodionov.I.A._COP_28/COP/RodionovLibrary/VisualComponents/ComboBoxControl.cs

52 lines
1.2 KiB
C#
Raw Normal View History

2024-09-05 23:36:10 +04:00
namespace RodionovLibrary.VisualComponents
{
public partial class ComboBoxControl : UserControl
{
private event EventHandler? _valueChanged;
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
public string SelectedValue
{
get
{
return comboBox.SelectedItem != null ? comboBox.SelectedItem.ToString()! : "";
}
set
{
if (comboBox.Items.Contains(value))
{
comboBox.SelectedItem = value;
}
}
}
public ComboBoxControl()
{
InitializeComponent();
}
public void AddItems(List<string> items)
{
foreach (string item in items)
{
comboBox.Items.Add(item);
}
}
public void Clear()
{
comboBox.Items.Clear();
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_valueChanged?.Invoke(sender, e);
}
}
}