KOP_Library_v5/ViewComponents/VisualComponents/List_with_choice.cs

57 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ViewComponents
{
public partial class List_with_choice : UserControl
{
public List_with_choice()
{
InitializeComponent();
}
public event Action<string?> SelectedItemChange;
public string? Element
{
get
{
if (checkedListBox1.SelectedItem != null) return checkedListBox1.SelectedItem.ToString();
else return string.Empty;
}
set
{
if (value != null && checkedListBox1.Items.Contains(value)) checkedListBox1.SelectedItem = value;
}
}
public void Fill_List(string str) //метод заполнения списка
{
if (str == null)
{
return;
}
checkedListBox1.Items.Add(str);
}
public void Clean_List() //метод очистки списка
{
checkedListBox1.Items.Clear();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedItemChange?.Invoke(checkedListBox1.SelectedItem.ToString());
}
}
}