namespace CustomsComponentsVar2; public partial class CustomCheckedListBox : UserControl { private event EventHandler? _selectedChanged; public CustomCheckedListBox() { InitializeComponent(); } public string SelectedElement { get { if (checkedListBox.Items.Count == 0 || checkedListBox.Items == null) { return String.Empty; } return checkedListBox.Items.ToString(); } set { if (checkedListBox.Items.Contains(value)) { checkedListBox.SelectedItem = value; } } } /// /// Добавить элементы /// /// public void addElements(List s) { checkedListBox.Items.Clear(); checkedListBox.Items.AddRange(s.ToArray()); } /// /// Выбран элемент /// /// /// private void onItemCheck(object sender, ItemCheckEventArgs e) { _selectedChanged?.Invoke(this, EventArgs.Empty); } /// /// Изменение индекса выбранного элемента /// /// /// private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e) { if (checkedListBox.CheckedItems.Count > 1) { foreach (int index in checkedListBox.CheckedIndices) { if (index != checkedListBox.SelectedIndex) { checkedListBox.SetItemChecked(index, false); } } } _selectedChanged?.Invoke(sender, e); } }