PIbd-31_Malafeev.L.S._COP_25/Cop_25/Controls/CustomComboBox.cs

96 lines
2.4 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;
namespace Controls
{
public partial class CustomComboBox : UserControl
{
/// <summary>
/// Конструктор
/// </summary>
public CustomComboBox()
{
InitializeComponent();
}
/// <summary>
/// Очищение списка
/// </summary>
public void ComboBoxClear()
{
comboBoxMain.Items.Clear();
comboBoxMain.SelectedItem = null;
}
/// <summary>
/// Выбранный элемент
/// </summary>
public string SelectedItem
{
get
{
if (comboBoxMain.Items.Count == 0)
{
return " ";
}
if (comboBoxMain.SelectedItem == null)
{
return " ";
}
return comboBoxMain.SelectedItem.ToString()!;
}
set
{
if (comboBoxMain.Items.Contains(value))
{
comboBoxMain.SelectedItem = value;
}
}
}
/// <summary>
/// Публичное свойство
/// </summary>
public ComboBox.ObjectCollection ComboBoxItems
{
get { return comboBoxMain.Items; }
}
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
private EventHandler _onValueChangedEvent;
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
/// <summary>
/// Смена значения
/// </summary>
private void CustomComboBox_SelectedValueChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}