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
|
|
|
|
|
{
|
2024-09-23 13:56:22 +04:00
|
|
|
|
return comboBox.SelectedItem?.ToString() ?? "";
|
2024-09-05 23:36:10 +04:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|