COP/COP_LabWork/CustomComponents/DropDownList.cs

71 lines
1.1 KiB
C#
Raw Normal View History

2024-07-29 20:10:28 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomComponents
{
public partial class DropDownList : UserControl
{
public DropDownList()
{
InitializeComponent();
}
public void AddToList(string value)// 1 zadanie
{
if (value == null)
{
return;
}
ComboBox.Items.Add(value);
}
public void ClearList()
{
ComboBox.Items.Clear();
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
public string? Selected
{
get
{
if (ComboBox.Items.Count == 0 || ComboBox.SelectedItem == null)
{
return "";
}
return ComboBox.SelectedItem.ToString()!;
}
set
{
if (ComboBox.Items.Contains(value))
{
ComboBox.SelectedItem = value;
}
}
}
private EventHandler _changeEvent;
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
}
}