75 lines
1.2 KiB
C#
75 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace VisualCompLib
|
|
{
|
|
public partial class MyDropDownList : UserControl
|
|
{
|
|
public MyDropDownList()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void LoadValues(List<string> Values)
|
|
{
|
|
if (Values.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
dropDownList.Items.AddRange(Values.ToArray());
|
|
}
|
|
public void Clear()
|
|
{
|
|
dropDownList.Items.Clear();
|
|
}
|
|
|
|
public string SelectedValue
|
|
{
|
|
get
|
|
{
|
|
if (dropDownList.Items.Count == 0)
|
|
{
|
|
return "";
|
|
}
|
|
if (dropDownList.SelectedItem == null)
|
|
{
|
|
return "";
|
|
}
|
|
return dropDownList.SelectedItem.ToString();
|
|
}
|
|
set
|
|
{
|
|
if (dropDownList.Items.Contains(value))
|
|
{
|
|
dropDownList.SelectedItem = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private EventHandler onValueChanged;
|
|
public event EventHandler ValueChanged
|
|
{
|
|
add
|
|
{
|
|
onValueChanged += value;
|
|
}
|
|
remove
|
|
{
|
|
onValueChanged -= value;
|
|
}
|
|
}
|
|
|
|
private void comboBox_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
onValueChanged?.Invoke(sender, e);
|
|
}
|
|
}
|
|
}
|