50 lines
949 B
C#
50 lines
949 B
C#
|
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;
|
|||
|
|
|||
|
namespace Components
|
|||
|
{
|
|||
|
public partial class CustomListBox : UserControl
|
|||
|
{
|
|||
|
private event EventHandler? _itemSelected;
|
|||
|
|
|||
|
public CustomListBox()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
public void SetItems(List<string> items)
|
|||
|
{
|
|||
|
listBox.Items.AddRange(items.ToArray());
|
|||
|
}
|
|||
|
|
|||
|
public void ClearList()
|
|||
|
{
|
|||
|
listBox.Items.Clear();
|
|||
|
}
|
|||
|
|
|||
|
public string SelectedItem
|
|||
|
{
|
|||
|
get { return (string?)listBox.SelectedItem ?? string.Empty; }
|
|||
|
set { listBox.SelectedItem = value; }
|
|||
|
}
|
|||
|
|
|||
|
public event EventHandler? ItemSelected
|
|||
|
{
|
|||
|
add { _itemSelected += value; }
|
|||
|
remove { _itemSelected -= value; }
|
|||
|
}
|
|||
|
|
|||
|
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_itemSelected?.Invoke(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|