COP-17/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs

79 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WinFormsLibrary
{
2023-10-05 11:23:18 +04:00
public partial class CustomCheckedListBox : UserControl
{
public CustomCheckedListBox()
{
InitializeComponent();
}
public void Clear()
{
checkedListBox.Items.Clear();
}
2023-10-05 11:23:18 +04:00
public CheckedListBox.ObjectCollection Items
{
2023-10-05 11:23:18 +04:00
get
{
return checkedListBox.Items;
}
}
public string Selected
{
get
2023-10-05 11:23:18 +04:00
{
if (checkedListBox.SelectedItem != null)
{
2023-10-05 11:23:18 +04:00
return checkedListBox.SelectedItem.ToString();
}
2023-10-05 11:23:18 +04:00
else
{
2023-10-05 11:23:18 +04:00
return "";
}
}
set
{
2023-10-05 11:23:18 +04:00
for (int i = 0; i < checkedListBox.Items.Count; ++i)
{
2023-10-05 11:23:18 +04:00
if (checkedListBox.Items[i].ToString() == value)
{
checkedListBox.SetItemChecked(i, true);
}
}
}
}
private EventHandler onValueChanged;
public event EventHandler ValueChanged
{
add
{
onValueChanged += value;
}
remove
{
onValueChanged -= value;
}
}
private void checkedListBox_SelectedValueChanged(object sender, EventArgs e)
{
onValueChanged?.Invoke(sender, e);
}
}
}