51 lines
917 B
C#
51 lines
917 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
|
|
{
|
|
int index = listBox.Items.IndexOf(value);
|
|
if (index != -1)
|
|
{
|
|
listBox.SelectedIndex = index;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
_itemSelected?.Invoke(this, e);
|
|
}
|
|
}
|
|
}
|