PIbd-31_Danilov_V_V_COP-30/Components/CustomListBox.cs

51 lines
917 B
C#
Raw Normal View History

2024-09-20 08:33:51 +04:00
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; }
2024-10-03 21:07:20 +04:00
set
{
int index = listBox.Items.IndexOf(value);
if (index != -1)
{
listBox.SelectedIndex = index;
}
}
2024-09-20 08:33:51 +04:00
}
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_itemSelected?.Invoke(this, e);
}
}
}