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; namespace PutincevLibrary { public partial class CheckedListBoxControl : UserControl { public CheckedListBoxControl() { InitializeComponent(); } private EventHandler _onCheckedItemChangedEvent; public event EventHandler CheckedItemChanged { add { _onCheckedItemChangedEvent += value; } remove { _onCheckedItemChangedEvent -= value; } } public string CheckedItem { get { return checkedListBox.CheckedItems[0] as string ?? string.Empty; } set { if (checkedListBox.Items.Contains(value)) { checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(value), CheckState.Checked); } } } public void SetCheckedListBoxValues(List values) { ClearCheckedListBoxValues(); foreach (var item in values) { checkedListBox.Items.Add(item); } } public void ClearCheckedListBoxValues() { checkedListBox.Items.Clear(); } private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { for (int i = 0; i < checkedListBox.Items.Count; i++) { if (i != e.Index) { checkedListBox.SetItemChecked(i, false); } } _onCheckedItemChangedEvent?.Invoke(sender, e); } } }