2023-09-15 15:37:37 +04:00
|
|
|
|
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 VisualComponentsLib
|
|
|
|
|
{
|
|
|
|
|
public partial class MyDropDownList: UserControl
|
|
|
|
|
{
|
|
|
|
|
public MyDropDownList()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadValues(List<string> Values)
|
|
|
|
|
{
|
|
|
|
|
if (Values.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-15 19:31:01 +04:00
|
|
|
|
dropDownList.Items.AddRange(Values.ToArray());
|
2023-09-15 15:37:37 +04:00
|
|
|
|
}
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
2023-09-15 19:31:01 +04:00
|
|
|
|
dropDownList.Items.Clear();
|
2023-09-15 15:37:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SelectedValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-09-15 19:31:01 +04:00
|
|
|
|
if (dropDownList.Items.Count == 0)
|
2023-09-15 15:37:37 +04:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2023-09-15 19:31:01 +04:00
|
|
|
|
if (dropDownList.SelectedItem == null)
|
2023-09-15 15:37:37 +04:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2023-09-15 19:31:01 +04:00
|
|
|
|
return dropDownList.SelectedItem.ToString();
|
2023-09-15 15:37:37 +04:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2023-09-15 19:31:01 +04:00
|
|
|
|
if (dropDownList.Items.Contains(value))
|
2023-09-15 15:37:37 +04:00
|
|
|
|
{
|
2023-09-15 19:31:01 +04:00
|
|
|
|
dropDownList.SelectedItem = value;
|
2023-09-15 15:37:37 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-16 11:05:11 +04:00
|
|
|
|
|
|
|
|
|
private EventHandler onValueChanged;
|
|
|
|
|
public event EventHandler ValueChanged
|
|
|
|
|
{
|
|
|
|
|
add
|
|
|
|
|
{
|
|
|
|
|
onValueChanged += value;
|
|
|
|
|
}
|
|
|
|
|
remove
|
|
|
|
|
{
|
|
|
|
|
onValueChanged -= value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 15:37:37 +04:00
|
|
|
|
private void comboBox_SelectedValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
onValueChanged?.Invoke(sender, e);
|
2023-09-15 15:37:37 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|