60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
namespace Components
|
|
{
|
|
public partial class UserControlCheckedList : UserControl
|
|
{
|
|
private EventHandler _onCheckedItemChangedEvent;
|
|
public event EventHandler CheckedItemChanged
|
|
{
|
|
add
|
|
{
|
|
_onCheckedItemChangedEvent += value;
|
|
}
|
|
remove
|
|
{
|
|
_onCheckedItemChangedEvent -= value;
|
|
}
|
|
}
|
|
public string CheckedItem
|
|
{
|
|
get
|
|
{
|
|
return checkedListBox.CheckedItems[0] as string ?? string.Empty;
|
|
}
|
|
set
|
|
{
|
|
if (checkedListBox.Items.Contains(value))
|
|
{
|
|
checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(value), CheckState.Checked);
|
|
}
|
|
}
|
|
}
|
|
public UserControlCheckedList()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public void SetCheckedListBoxValues(List<string> values)
|
|
{
|
|
ClearCheckedListBoxValues();
|
|
foreach (var item in values)
|
|
{
|
|
checkedListBox.Items.Add(item);
|
|
}
|
|
}
|
|
public void ClearCheckedListBoxValues()
|
|
{
|
|
checkedListBox.Items.Clear();
|
|
}
|
|
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
|
|
{
|
|
for (int i = 0; i < checkedListBox.Items.Count; i++)
|
|
{
|
|
if (i != e.Index)
|
|
{
|
|
checkedListBox.SetItemChecked(i, false);
|
|
}
|
|
}
|
|
_onCheckedItemChangedEvent?.Invoke(sender, e);
|
|
}
|
|
}
|
|
}
|