PIbd-31_Danilov_V_V_COP-30/Components/Visual/CustomListBox.cs
Владимир Данилов 4d673aa1dc В процессе
2024-10-16 14:03:22 +04:00

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);
}
}
}