【问题标题】:Distinguish between clicking the displayed item and clicking an item in the drop-down list in a ComboBox区分单击显示的项目和单击组合框中下拉列表中的项目
【发布时间】:2021-07-14 09:56:32
【问题描述】:

我想知道如何区分单击显示的项目和单击组合框下拉列表中的项目之一。

【问题讨论】:

  • ComboBox 使用的是什么DropDownStyle
  • @Matthew Watson comboBox1.DropDownStyle = ComboBoxStyle.DropDown;

标签: c# winforms events combobox


【解决方案1】:

...区分单击显示的项目和单击下拉列表中的项目之一

我假设您想知道操作员是重新选择最后选择的项目(即显示的项目),还是选择新的项目(在下拉列表中。

您需要一个属性来访问操作员选择的项目:

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);
}

【讨论】:

  • 非常感谢。我假设有一个内置事件来区分这两种选择点击。
猜你喜欢
  • 2011-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-30
  • 1970-01-01
相关资源
最近更新 更多