From d5384363ab6965aef46ede098ade193882c30658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Wed, 27 Nov 2024 23:40:10 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20checkedlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавил возможность указать максимальное количество чекнутых Item; При достижении макс. количества последний чекнутый становится не чекнутым; --- .../Components/UserControlCheckedList.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/WinFormSolution/Components/UserControlCheckedList.cs b/WinFormSolution/Components/UserControlCheckedList.cs index 018025a..e18ff56 100644 --- a/WinFormSolution/Components/UserControlCheckedList.cs +++ b/WinFormSolution/Components/UserControlCheckedList.cs @@ -2,6 +2,8 @@ { public partial class UserControlCheckedList : UserControl { + private List _lastCheckedIndexes = new List(); + public int MaxCheckedItemsCount { get; set; } = 1; private EventHandler _onCheckedItemChangedEvent; public event EventHandler CheckedItemChanged { @@ -43,16 +45,24 @@ public void ClearCheckedListBoxValues() { checkedListBox.Items.Clear(); + _lastCheckedIndexes.Clear(); } private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { - for (int i = 0; i < checkedListBox.Items.Count; i++) + if (e.NewValue == CheckState.Checked) { - if (i != e.Index) + _lastCheckedIndexes.Add(e.Index); + + while (_lastCheckedIndexes.Count > MaxCheckedItemsCount) { - checkedListBox.SetItemChecked(i, false); + checkedListBox.SetItemCheckState(_lastCheckedIndexes[0], CheckState.Unchecked); } } + else if (e.NewValue == CheckState.Unchecked) + { + _lastCheckedIndexes.Remove(e.Index); + } + _onCheckedItemChangedEvent?.Invoke(sender, e); } } -- 2.25.1 From 811e94e0ce7005d843e6b6a5dec7188a23d5bb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Wed, 27 Nov 2024 23:41:08 +0400 Subject: [PATCH 2/2] Bump version 1.0.2 -> 1.0.3 --- WinFormSolution/Components/Components.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinFormSolution/Components/Components.csproj b/WinFormSolution/Components/Components.csproj index 1d227a6..f6cdb74 100644 --- a/WinFormSolution/Components/Components.csproj +++ b/WinFormSolution/Components/Components.csproj @@ -7,7 +7,7 @@ enable True ns.potapov - 1.0.2 + 1.0.3 $(VersionPrefix) -- 2.25.1