【发布时间】:2021-07-14 09:56:32
【问题描述】:
我想知道如何区分单击显示的项目和单击组合框下拉列表中的项目之一。
【问题讨论】:
-
ComboBox 使用的是什么
DropDownStyle? -
@Matthew Watson comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
标签: c# winforms events combobox
我想知道如何区分单击显示的项目和单击组合框下拉列表中的项目之一。
【问题讨论】:
DropDownStyle?
标签: c# winforms events combobox
...区分单击显示的项目和单击下拉列表中的项目之一
我假设您想知道操作员是重新选择最后选择的项目(即显示的项目),还是选择新的项目(在下拉列表中。
您需要一个属性来访问操作员选择的项目:
private MyType SelectedItem => (MyType)this.comboBox1.SelectedValue;
private MyType LastProcessedSelectedItem {get; set;} = null;
private void OnOperatorSelectedItem(MyType selectedItem)
{
if (this.LastProcessedSelectedItem != selectedItem)
{
this.OperatorSelectedDropDown();
}
else
{
this.OperatorSelectedDisplayed();
}
this.LastProcessedSelectedItem = selectedItem;
}
private void OnComboBox1_Clicked(object sender, ...)
{
MyType selectedItem = this.SelectedItem;
OnOperatorSelectedItem(selectedItem);
}
【讨论】: