COP_Petrushin_PIbd-32/Library14Petrushin/ChooseList.cs
2024-09-15 23:31:11 +04:00

58 lines
1.4 KiB
C#

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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Library14Petrushin
{
public partial class ChooseList : UserControl
{
public event EventHandler? SelectedValueChanged;
public string SelectedValue
{
get
{
return checkedListBox1.SelectedItem?.ToString() ?? string.Empty;
}
set
{
int index = checkedListBox1.Items.IndexOf(value);
if (index >= 0)
{
checkedListBox1.SelectedIndex = index;
}
else
{
checkedListBox1.ClearSelected();
}
}
}
public ChooseList()
{
InitializeComponent();
}
public void AddItemToList(string item)
{
checkedListBox1.Items.Add(item);
}
private void SelectedIndexChanged(object sender, EventArgs e)
{
SelectedValueChanged?.Invoke(this, e);
}
public void ClearComboBox()
{
checkedListBox1.Items.Clear();
}
}
}