using DocumentFormat.OpenXml.Spreadsheet; namespace COP { public partial class UserCheckedListBox : UserControl { private event EventHandler? _selectedValueChanged; public UserCheckedListBox() { InitializeComponent(); } public void FillList(List 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 { return string.Join(";", checkedListBox.CheckedItems.Cast()); } set { if (!string.IsNullOrEmpty(value)) { string[] selectedValues = value.Split(';'); for (int i = 0; i < checkedListBox.Items.Count; i++) { checkedListBox.SetItemChecked(i, selectedValues.Contains(checkedListBox.Items[i].ToString()) || checkedListBox.GetItemChecked(i)); } } } } public event EventHandler SelectedValueChanged { add { _selectedValueChanged += value; } remove { _selectedValueChanged += value; } } private void CheckedListBox_SelectedIndexChanged(object sender, EventArgs e) { _selectedValueChanged?.Invoke(this, e); } } }