53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
namespace CustomComponents
|
|
{
|
|
public partial class Frame : UserControl
|
|
{
|
|
|
|
|
|
private string? SelectedValue = string.Empty;
|
|
|
|
public event EventHandler ValueChanged;
|
|
|
|
public Frame()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void PopulateList(List<string> data)
|
|
{
|
|
if (data.Count == 0 || data is null)
|
|
{
|
|
return;
|
|
}
|
|
listBox.Items.AddRange(data.ToArray<object>());
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
listBox.Items.Clear();
|
|
}
|
|
|
|
public string? Value
|
|
{
|
|
get
|
|
{
|
|
if (listBox.SelectedItem is null)
|
|
{
|
|
return "";
|
|
}
|
|
return SelectedValue;
|
|
}
|
|
set
|
|
{
|
|
SelectedValue = value;
|
|
}
|
|
}
|
|
|
|
private void SelectedValue_Changed(object sender, EventArgs e)
|
|
{
|
|
var element = sender as ListBox;
|
|
Value = element.Text.ToString();
|
|
ValueChanged?.Invoke(this, e);
|
|
}
|
|
}
|
|
} |