PIbd-31_Alekseev.I.S._COP_3/FormLibrary/CustomListBox.cs
Иван Алексеев 1128ffdc1a сдано
2024-09-21 17:41:05 +04:00

49 lines
1.2 KiB
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace FormLibrary
{
public partial class CustomListBox : UserControl
{
public event EventHandler? SelectedItemChanged;
public CustomListBox()
{
InitializeComponent();
}
public string SelectedItem
{
get => listBox1.SelectedItem?.ToString() ?? string.Empty;
set => listBox1.SelectedIndex = listBox1.Items.IndexOf(value);
}
private void ListBox1_SelectedIndexChanged(object? sender, EventArgs e)
{
SelectedItemChanged?.Invoke(this, EventArgs.Empty);
}
public void PopulateListBox(List<string> items)
{
listBox1.Items.Clear();
foreach (var item in items)
{
listBox1.Items.Add(item);
}
}
public void ClearListBox()
{
listBox1.Items.Clear();
}
}
}