2024-09-05 21:45:49 +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 Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class CustomComboBox : UserControl
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CustomComboBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Очищение списка
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ComboBoxClear()
|
|
|
|
|
{
|
|
|
|
|
comboBoxMain.Items.Clear();
|
2024-09-06 00:43:56 +04:00
|
|
|
|
comboBoxMain.SelectedItem = null;
|
2024-09-05 21:45:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбранный элемент
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxMain.Items.Count == 0)
|
|
|
|
|
{
|
2024-09-06 00:43:56 +04:00
|
|
|
|
return " ";
|
2024-09-05 21:45:49 +04:00
|
|
|
|
}
|
|
|
|
|
if (comboBoxMain.SelectedItem == null)
|
|
|
|
|
{
|
2024-09-06 00:43:56 +04:00
|
|
|
|
return " ";
|
2024-09-05 21:45:49 +04:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|