【问题标题】:Toolstrip combobox onselectionchangecommitted not working工具条组合框 onselectionchangecommitted 不起作用
【发布时间】:2016-05-23 23:38:32
【问题描述】:

当用户在 Winform 上的工具条组合框中进行鼠标选择并且一直试图让 OnSelectionChangeCommitted 工作(链接 here)类似于 this 问题时,我试图触发一些代码。我不能使用SelectedIndexChanged 方法,因为当用户单击组合框时会自动选择第一项,然后触发代码,我不想使用焦点或布尔值。

当用户在组合框中进行选择时,下面的代码不会触发,我做错了什么?

protected virtual void bxDEAL_SELECT_OnSelectionChangeCommitted(EventArgs e)
        {
            MessageBox.Show("onselect value changed");
        }

【问题讨论】:

  • 那个方法签名是错误的。它缺少Object sender 参数。您不能将此方法与事件挂钩,否则将无法编译。

标签: c# winforms combobox event-handling toolstrip


【解决方案1】:

你的 sender 参数在哪里?

它应该看起来像这样

private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
     // your code
}

【讨论】:

  • 您是否尝试将 if 语句放入 slectedIndexChanged 中?
  • 在事件之外放置一个整数值 -1 并检查 selectedIndex = value 如果不是那个值,您可以运行您的代码...然后设置 value = slectedIndex
  • 处理程序未连接,或者缺少sender 参数会触发编译器错误。
  • @DonBoitnott 我同意,我找不到组合框属性/事件中列出的OnSelectionChangeCommitted 事件,所以我手动输入了它。我想这不会挂钩。正确的方法是什么?
  • comboBox1.SelectionChangeCommitted += comboBox1_SelectionChangeCommitted;
【解决方案2】:

你需要调用底层的 ComboBox 对象来访问提交的事件。

bxDEAL_SELECT.ComboBox.SelectionChangeCommitted += ComboBoxOnSelectionChangeCommitted;

private void bxDEAL_SELECT_OnSelectionChangeCommitted(object o, EventArgs eventArgs)
{
    \\Your code goes here.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 2016-06-09
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多