COP_Petrushin_PIbd-32/Library14Petrushin/ChooseList.cs
2024-09-17 12:40:52 +04:00

71 lines
1.8 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);
}
private void CheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (i != e.Index)
{
checkedListBox1.SetItemChecked(i, false);
}
}
}
}
public void ClearComboBox()
{
checkedListBox1.Items.Clear();
}
}
}