Merge pull request 'fix' (#3) from lab2_fix_fix into lab2_fix
Reviewed-on: #3
This commit is contained in:
commit
062f92babb
@ -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();
|
||||
@ -50,10 +82,18 @@ namespace Components
|
||||
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
|
||||
{
|
||||
if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount)
|
||||
{
|
||||
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