KOP_Library_v5/ViewComponents/List_with_choice.cs

62 lines
1.3 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)
{
MessageBox.Show("Вы не ввели строку");
return;
}
string[] list = str.Split(' ');
foreach (string s in list)
{
checkedListBox1.Items.Add(s);
}
}
public void Clean_List() //метод очистки списка
{
checkedListBox1.Items.Clear();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedItemChange?.Invoke(checkedListBox1.SelectedItem.ToString());
}
}
}