none
为什么在 VSTO 开发 Excel AddIn 环境中, Excel 点击的 “全部刷新” 的按键会导致自定义 CommandBarButton 的 Click 事件失效? RRS feed

  • 问题

  • 为什么在 VSTO 开发 Excel AddIn 环境中, Excel 点击的  “数据”  > "数据和连接" > “全部刷新” 按键会导致自定义 CommandBarButton 的 Click 事件失效?

    在不点击 “数据”  > "数据和连接" > “全部刷新” 按键的情况下,自定义 CommandBarButton 的 Click 是会一直生效的。

    下面是我创建 CommandBar 的代码:

    CommandBar contextMenu = Globals.ThisAddIn.Application.CommandBars.Add(menuName, MsoBarPosition.msoBarPopup);
                for (int index = 0; index < listObject.Source.ListRows.Count; index++)
                {
                    string tagContxt = "";
                    CommandBarPopup tempContextMenu = null;
                    foreach (ListColumn listColumn in listObject.Source.ListColumns)
                    {
                        tagContxt += listObject.GetValue(index, listColumn.Name);
                        CommandBarPopup popupMenu = (CommandBarPopup)contextMenu.FindControl(MsoControlType.msoControlPopup, Type.Missing, CommonHelper.MD5(tagContxt), true, true);
                        if (popupMenu == null)
                        {
                            if (listColumn.Name != keyValue)
                            {
                                if (tempContextMenu == null)
                                {
                                    popupMenu = (CommandBarPopup)contextMenu.Controls.Add(MsoControlType.msoControlPopup);
                                }
                                else
                                {
                                    popupMenu = (CommandBarPopup)tempContextMenu.Controls.Add(MsoControlType.msoControlPopup);
                                }
                                popupMenu.Caption = listObject.GetValue(index, listColumn.Name);
                                popupMenu.Tag = CommonHelper.MD5(tagContxt);
                                popupMenu.BeginGroup = true;
                            }
                            else
                            {
                                CommandBarButton buttonMenu = null;
                                if (tempContextMenu == null)
                                {
                                    buttonMenu = (CommandBarButton)contextMenu.Controls.Add(MsoControlType.msoControlButton);
                                }
                                else
                                {
                                    buttonMenu = (CommandBarButton)tempContextMenu.Controls.Add(MsoControlType.msoControlButton);
                                }
                                buttonMenu.Caption = listObject.GetValue(index, listColumn.Name);
                                buttonMenu.Tag = menuName + listObject.GetValue(index, listColumn.Name);
                                buttonMenu.FaceId = 0162;
                                buttonMenu.Click += new _CommandBarButtonEvents_ClickEventHandler(ButtonMenu_Click);
                            }
                        }
                        tempContextMenu = popupMenu;
                    }
                }


    2021年2月9日 5:18

全部回复

  • 你好,

    由于您的问题和vsto更相关,我建议您可以在以下论坛提问。

    office-vsto-com-dev

    此论坛只讨论与c#相关的语言,技术,以及IDE。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2021年2月9日 8:28