mirror of
https://github.com/kwsch/NHSE.git
synced 2026-03-27 12:04:46 -05:00
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using NHSE.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace NHSE.WinForms;
|
|
|
|
public partial class RestrictedItemSelect : UserControl
|
|
{
|
|
private IList<ComboItem> DataSource = [];
|
|
|
|
public RestrictedItemSelect() => InitializeComponent();
|
|
|
|
public void Initialize(IList<ComboItem> items, bool canType = false)
|
|
{
|
|
CB_ItemID.DisplayMember = nameof(ComboItem.Text);
|
|
CB_ItemID.ValueMember = nameof(ComboItem.Value);
|
|
CB_ItemID.DataSource = DataSource = items;
|
|
|
|
if (!canType)
|
|
CB_ItemID.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
}
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public ushort Value
|
|
{
|
|
get => CHK_CustomItem.Checked ? (ushort) NUD_CustomItem.Value : (ushort) WinFormsUtil.GetIndex(CB_ItemID);
|
|
set
|
|
{
|
|
if (DataSource.Any(z => z.Value == value))
|
|
{
|
|
CHK_CustomItem.Checked = false;
|
|
CB_ItemID.SelectedValue = (int)value;
|
|
}
|
|
else
|
|
{
|
|
CHK_CustomItem.Checked = true;
|
|
NUD_CustomItem.Value = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CHK_Custom_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
CB_ItemID.Enabled = !CHK_CustomItem.Checked;
|
|
NUD_CustomItem.Enabled = CHK_CustomItem.Checked;
|
|
}
|
|
|
|
private void CB_ItemID_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
NUD_CustomItem.Value = WinFormsUtil.GetIndex(CB_ItemID);
|
|
}
|
|
} |