переписал обработку при изменении itemcheck
теперь обрабатывается после срабатывания
This commit is contained in:
parent
315c6f7249
commit
0221ad1e7a
@ -7,7 +7,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Authors>ns.potapov</Authors>
|
||||
<VersionPrefix>1.0.6</VersionPrefix>
|
||||
<VersionPrefix>1.0.7</VersionPrefix>
|
||||
<Version>$(VersionPrefix)</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -36,22 +36,20 @@
|
||||
checkedListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
checkedListBox.CheckOnClick = true;
|
||||
checkedListBox.FormattingEnabled = true;
|
||||
checkedListBox.Location = new Point(9, 8);
|
||||
checkedListBox.Margin = new Padding(3, 4, 3, 4);
|
||||
checkedListBox.Location = new Point(8, 6);
|
||||
checkedListBox.Name = "checkedListBox";
|
||||
checkedListBox.Size = new Size(509, 400);
|
||||
checkedListBox.Size = new Size(446, 292);
|
||||
checkedListBox.TabIndex = 0;
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
//
|
||||
// UserControlCheckedList
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
BackColor = Color.Firebrick;
|
||||
Controls.Add(checkedListBox);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "UserControlCheckedList";
|
||||
Size = new Size(527, 415);
|
||||
Size = new Size(461, 311);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Components.Exceptions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
@ -44,15 +45,15 @@ namespace Components
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<string> CheckedItems
|
||||
public List<string> CheckedItemss
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
foreach(var item in checkedListBox.CheckedItems )
|
||||
foreach (var item in checkedListBox.CheckedItems)
|
||||
{
|
||||
list.Add(item.ToString());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
set
|
||||
@ -84,20 +85,24 @@ namespace Components
|
||||
}
|
||||
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
|
||||
{
|
||||
if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount)
|
||||
this.BeginInvoke((MethodInvoker)(
|
||||
() =>
|
||||
{
|
||||
if (typeOfMaxChecked == Types.Exception)
|
||||
if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount)
|
||||
{
|
||||
checkedListBox.SetItemChecked(e.Index, false);
|
||||
throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов");
|
||||
if (typeOfMaxChecked == Types.Exception)
|
||||
{
|
||||
MessageBox.Show("Превышено максимальное число выбранных элементов");
|
||||
checkedListBox.SetItemChecked(e.Index, false);
|
||||
}
|
||||
else if (typeOfMaxChecked == Types.DeleteFirst)
|
||||
{
|
||||
checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(CheckedItem), CheckState.Unchecked);
|
||||
}
|
||||
|
||||
}
|
||||
else if (typeOfMaxChecked == Types.DeleteFirst)
|
||||
{
|
||||
checkedListBox.SetItemChecked(0, false);
|
||||
}
|
||||
|
||||
}
|
||||
_onCheckedItemChangedEvent?.Invoke(sender, e);
|
||||
_onCheckedItemChangedEvent?.Invoke(sender, e);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ namespace WinFormsApp
|
||||
list.Add("Çíàòü");
|
||||
list.Add("C#");
|
||||
userControlCheckedList.SetCheckedListBoxValues(list);
|
||||
|
||||
userControlCheckedList.CheckedItem = list[3];
|
||||
userControlCheckedList.MaxCheckedItemsCount = 3;
|
||||
userControlCheckedList.ChangeTypeOfMaxChecked(Components.Types.DeleteFirst);
|
||||
}
|
||||
|
||||
private void buttonClearList_Click(object sender, EventArgs e)
|
||||
|
@ -11,7 +11,7 @@ namespace WinFormsApp
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormNoVisual());
|
||||
Application.Run(new FormVisual());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user