PIbd-31_Razubaev_S_M_COP-10/WinFormsLibrary/DropDownList.cs

61 lines
1.0 KiB
C#
Raw Normal View History

namespace WinFormsLibrary
{
public partial class DropDownList : UserControl
{
public DropDownList()
{
InitializeComponent();
}
public void Clear()
{
comboBox.Items.Clear();
}
public void LoadValues(List<string> values)
{
if (values.Count == 0)
{
return;
}
comboBox.Items.AddRange(values.ToArray());
}
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;
}
}
}
public ComboBox.ObjectCollection comboBoxItems
{
get { return comboBox.Items; }
}
private EventHandler _onValueChanged;
public event EventHandler ValueChanged
{
add { _onValueChanged += value; }
remove { _onValueChanged -= value; }
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_onValueChanged?.Invoke(sender, e);
}
}
}