From c853d7790c9d93d0de52f7afd92b2ca615c81b27 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: Thu, 28 Nov 2024 00:02:15 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20CheckedListBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaxCheckedItemsCountExceedException.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 WinFormSolution/Components/Exceptions/MaxCheckedItemsCountExceedException.cs diff --git a/WinFormSolution/Components/Exceptions/MaxCheckedItemsCountExceedException.cs b/WinFormSolution/Components/Exceptions/MaxCheckedItemsCountExceedException.cs new file mode 100644 index 0000000..666aca6 --- /dev/null +++ b/WinFormSolution/Components/Exceptions/MaxCheckedItemsCountExceedException.cs @@ -0,0 +1,13 @@ +namespace Components.Exceptions +{ + internal class MaxCheckedItemsCountExceedException : Exception + { + public MaxCheckedItemsCountExceedException() + { + } + + public MaxCheckedItemsCountExceedException(string? message) : base(message) + { + } + } +} -- 2.25.1 From 48fc1a8443ad98f68f0cfcc153f7dae5db0dd56e 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: Thu, 28 Nov 2024 00:02:40 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B1=D1=80=D0=BE=D1=81=20=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20CheckedListBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/UserControlCheckedList.cs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/WinFormSolution/Components/UserControlCheckedList.cs b/WinFormSolution/Components/UserControlCheckedList.cs index e18ff56..c37cf14 100644 --- a/WinFormSolution/Components/UserControlCheckedList.cs +++ b/WinFormSolution/Components/UserControlCheckedList.cs @@ -1,8 +1,9 @@ -namespace Components +using Components.Exceptions; + +namespace Components { public partial class UserControlCheckedList : UserControl { - private List _lastCheckedIndexes = new List(); public int MaxCheckedItemsCount { get; set; } = 1; private EventHandler _onCheckedItemChangedEvent; public event EventHandler CheckedItemChanged @@ -45,24 +46,14 @@ public void ClearCheckedListBoxValues() { checkedListBox.Items.Clear(); - _lastCheckedIndexes.Clear(); } private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { - if (e.NewValue == CheckState.Checked) + if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount) { - _lastCheckedIndexes.Add(e.Index); - - while (_lastCheckedIndexes.Count > MaxCheckedItemsCount) - { - checkedListBox.SetItemCheckState(_lastCheckedIndexes[0], CheckState.Unchecked); - } + checkedListBox.SetItemChecked(e.Index, false); + throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов"); } - else if (e.NewValue == CheckState.Unchecked) - { - _lastCheckedIndexes.Remove(e.Index); - } - _onCheckedItemChangedEvent?.Invoke(sender, e); } } -- 2.25.1 From 77b1ea495fa716ede88b7d17dff7e21508d60345 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: Thu, 28 Nov 2024 00:03:18 +0400 Subject: [PATCH 3/3] Bump version 1.0.3 -> 1.0.4 --- 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 f6cdb74..0d2190a 100644 --- a/WinFormSolution/Components/Components.csproj +++ b/WinFormSolution/Components/Components.csproj @@ -7,7 +7,7 @@ enable True ns.potapov - 1.0.3 + 1.0.4 $(VersionPrefix) -- 2.25.1