2024-10-29 09:22:02 +04:00

54 lines
1.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 BulatovaComponents.Components
{
public partial class ComboBoxControl : UserControl
{
public ComboBoxControl()
{
InitializeComponent();
}
public string SelectedValue
{
get
{
return comboBoxCustom.SelectedItem != null ? comboBoxCustom.SelectedItem.ToString() : "";
}
set
{
if (comboBoxCustom.Items.Contains(value)) //если есть такой элемент, то помечаем, если нет, ничего не делаем
{
comboBoxCustom.SelectedItem = value;
}
}
}
public event Action<string?> SelectedValueChange;
public void addItems(List<string> items)
{
foreach (string item in items)
{
comboBoxCustom.Items.Add(item);
}
}
public void clear()
{
comboBoxCustom.Items.Clear();
}
private void comboBoxCustom_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedValueChange?.Invoke(comboBoxCustom.SelectedItem.ToString());
}
}
}