简体   繁体   English

通过功能区下拉列表中的代码更改选择时不会触发SelectionChanged事件

[英]SelectionChanged event is not fired when selection is changed through code in ribbon dropdown

I have created an excel ribbon. 我创建了一个Excel功能区。 It contains a button and a dropdown. 它包含一个按钮和一个下拉菜单。 The dropdown contains some items. 下拉菜单包含一些项目。

Now, in the SelectionChanged event of dropdown, I am displaying the label of selected item in MessageBox and it is getting displayed. 现在,在下拉列表的SelectionChanged事件中,我在MessageBox中显示所选项目的标签,并且该标签正在显示。

But when I am trying to change the index of dropdown on the button click, the selected item changes but the event is not fired. 但是,当我尝试更改按钮单击时的下拉索引时,所选项目会更改,但不会触发该事件。

What am I doing wrong? 我究竟做错了什么? Am I missing something? 我想念什么吗? Same thing works fine in Windows form application. 同样的东西在Windows窗体应用程序中也能正常工作。

Here is the code: 这是代码:

    private void DD_SelectionChanged(object sender, RibbonControlEventArgs e)
    {
        MessageBox.Show(DD.SelectedItem.Label);
    }

    private void btnChange_Click(object sender, RibbonControlEventArgs e)
    {
        DD.SelectedItemIndex = 3;
    }

只需直接从btnChange_Click调用DD_SelectionChanged。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM