PIbd-32_Artamonova_T.V._COP_2/COP/UserCheckedListBox.cs

60 lines
1.6 KiB
C#
Raw Permalink Normal View History

2023-11-09 04:07:06 +04:00
using DocumentFormat.OpenXml.Spreadsheet;
namespace COP
2023-10-12 18:40:10 +04:00
{
public partial class UserCheckedListBox : UserControl
{
private event EventHandler? _selectedValueChanged;
public UserCheckedListBox()
{
InitializeComponent();
}
public void FillList(List<string> items)
{
if (items.Count == 0 || items is null)
{
return;
}
checkedListBox.Items.Clear();
checkedListBox.Items.AddRange(items.ToArray());
}
public void ClearList()
{
checkedListBox.Items.Clear();
}
public string SelectedValue
{
get
{
2023-11-09 04:07:06 +04:00
return string.Join(";", checkedListBox.CheckedItems.Cast<string>());
2023-10-12 18:40:10 +04:00
}
set
{
2023-11-09 04:07:06 +04:00
if (!string.IsNullOrEmpty(value))
2023-10-12 18:40:10 +04:00
{
2023-11-09 04:07:06 +04:00
string[] selectedValues = value.Split(';');
for (int i = 0; i < checkedListBox.Items.Count; i++)
2023-10-12 18:40:10 +04:00
{
2023-11-09 04:07:06 +04:00
checkedListBox.SetItemChecked(i, selectedValues.Contains(checkedListBox.Items[i].ToString()) || checkedListBox.GetItemChecked(i));
2023-10-12 18:40:10 +04:00
}
}
}
}
public event EventHandler SelectedValueChanged
{
add { _selectedValueChanged += value; }
remove { _selectedValueChanged += value; }
}
private void CheckedListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_selectedValueChanged?.Invoke(this, e);
}
}
}