PIbd-32_Turner_I.A._COP_10/COP/VisualCompLib/MyDropDownList.cs

75 lines
1.2 KiB
C#
Raw Permalink Normal View History

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;
2023-09-28 20:53:57 +04:00
namespace VisualCompLib
2023-09-15 15:37:37 +04:00
{
public partial class MyDropDownList : UserControl
{
public MyDropDownList()
{
InitializeComponent();
}
2023-09-15 15:37:37 +04:00
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
}
}
}