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

62 lines
1.2 KiB
C#
Raw 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;
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
}
}
}
private void comboBox_SelectedValueChanged(object sender, EventArgs e)
{
2023-09-15 19:31:01 +04:00
if (dropDownList.BackColor == Color.LightGreen) dropDownList.BackColor = Color.Tomato;
else dropDownList.BackColor = Color.LightGreen;
2023-09-15 15:37:37 +04:00
}
}
}