PIbd-32_Shabunov_O.A._COP/ShabComponentsLibrary/ShabSelectComponent.cs
2024-09-10 21:45:18 +04:00

59 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace ShabComponentsLibrary
{
/// <summary>
/// Визуальный компонент для выбора из обычного списка
/// </summary>
public partial class ShabSelectComponent : UserControl
{
private event EventHandler? _itemSelected;
public ShabSelectComponent()
{
InitializeComponent();
}
/// <summary>
/// Метод, у которого в передаваемых параметрах идет список строк
/// </summary>
/// <param name="Items">Список строк</param>
public void SetItems(List<string> Items)
{
foreach (var Item in Items)
{
MainListBox.Items.Add(Item);
}
}
/// <summary>
/// Очистка списка
/// </summary>
public void ClearList()
{
MainListBox.Items.Clear();
}
/// <summary>
/// Установка и получение выбранного значения
/// </summary>
public string SelectedItem
{
get { return (string?)MainListBox.SelectedItem ?? string.Empty; }
set { MainListBox.SelectedItem = value; }
}
/// <summary>
/// Событие, вызываемое при смене значения в ListBox
/// </summary>
public event EventHandler? ItemSelected
{
add { _itemSelected += value; }
remove { _itemSelected -= value; }
}
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_itemSelected?.Invoke(this, e);
}
}
}