fix
This commit is contained in:
parent
77b1ea495f
commit
340c7d9b1f
@ -7,7 +7,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Authors>ns.potapov</Authors>
|
||||
<VersionPrefix>1.0.4</VersionPrefix>
|
||||
<VersionPrefix>1.0.5</VersionPrefix>
|
||||
<Version>$(VersionPrefix)</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -2,10 +2,23 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
public enum Types : int
|
||||
{
|
||||
Exception = 0,
|
||||
DeleteFirst = 1,
|
||||
|
||||
}
|
||||
|
||||
|
||||
public partial class UserControlCheckedList : UserControl
|
||||
{
|
||||
public int MaxCheckedItemsCount { get; set; } = 1;
|
||||
private Types typeOfMaxChecked = Types.DeleteFirst;
|
||||
private EventHandler _onCheckedItemChangedEvent;
|
||||
public void ChangeTypeOfMaxChecked(Types type)
|
||||
{
|
||||
typeOfMaxChecked = type;
|
||||
}
|
||||
public event EventHandler CheckedItemChanged
|
||||
{
|
||||
add
|
||||
@ -31,6 +44,25 @@ namespace Components
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<string> CheckedItems
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
foreach(var item in checkedListBox.CheckedItems )
|
||||
{
|
||||
list.Add(item.ToString());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (checkedListBox.Items.Contains(value))
|
||||
{
|
||||
checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(value), CheckState.Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
public UserControlCheckedList()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -51,8 +83,16 @@ namespace Components
|
||||
{
|
||||
if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount)
|
||||
{
|
||||
checkedListBox.SetItemChecked(e.Index, false);
|
||||
throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов");
|
||||
if (typeOfMaxChecked == Types.Exception)
|
||||
{
|
||||
checkedListBox.SetItemChecked(e.Index, false);
|
||||
throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов");
|
||||
}
|
||||
else if (typeOfMaxChecked == Types.DeleteFirst)
|
||||
{
|
||||
checkedListBox.SetItemChecked(0, false);
|
||||
}
|
||||
|
||||
}
|
||||
_onCheckedItemChangedEvent?.Invoke(sender, e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user