Merge pull request 'lab2_fix' (#1) from lab2_fix into lab2
Reviewed-on: #1
This commit is contained in:
commit
f128da5093
@ -7,7 +7,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Authors>ns.potapov</Authors>
|
<Authors>ns.potapov</Authors>
|
||||||
<VersionPrefix>1.0.2</VersionPrefix>
|
<VersionPrefix>1.0.3</VersionPrefix>
|
||||||
<Version>$(VersionPrefix)</Version>
|
<Version>$(VersionPrefix)</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
{
|
{
|
||||||
public partial class UserControlCheckedList : UserControl
|
public partial class UserControlCheckedList : UserControl
|
||||||
{
|
{
|
||||||
|
private List<int> _lastCheckedIndexes = new List<int>();
|
||||||
|
public int MaxCheckedItemsCount { get; set; } = 1;
|
||||||
private EventHandler _onCheckedItemChangedEvent;
|
private EventHandler _onCheckedItemChangedEvent;
|
||||||
public event EventHandler CheckedItemChanged
|
public event EventHandler CheckedItemChanged
|
||||||
{
|
{
|
||||||
@ -43,16 +45,24 @@
|
|||||||
public void ClearCheckedListBoxValues()
|
public void ClearCheckedListBoxValues()
|
||||||
{
|
{
|
||||||
checkedListBox.Items.Clear();
|
checkedListBox.Items.Clear();
|
||||||
|
_lastCheckedIndexes.Clear();
|
||||||
}
|
}
|
||||||
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
|
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);
|
_onCheckedItemChangedEvent?.Invoke(sender, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user