加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 如何在Excel自定义功能区控件的下拉控件中设置默认值

发布时间:2020-12-16 05:36:13 所属栏目:百科 来源:网络整理
导读:我为Excel 2010创建了一个自定义的Fluent Ribbon界面,其中包含一个下拉列表.相关的 XML代码(简化): dropDown id="chooseFilter" showLabel="true" label="Filter" onAction="filterSelected" item id="Filter1" label="Filter 1" / item id="Filter2" label
我为Excel 2010创建了一个自定义的Fluent Ribbon界面,其中包含一个下拉列表.相关的 XML代码(简化):
<dropDown id="chooseFilter" showLabel="true" label="Filter" onAction="filterSelected" > 
    <item id="Filter1" label="Filter 1" /> 
    <item id="Filter2" label="Filter 2" /> 
</dropDown>

加载功能区时,未选择任何值 – 下拉列表显示为空.

我希望默认情况下选择第一个项目 – 但找不到任何描述如何操作的文档.我看了MSDN documentation的控件,但它没有涵盖这种情况.我尝试了各种“HTML-like”语句的排列,但它们都被自定义UI编辑器拒绝为无效.我试过的事情的例子:

<item id="Filter1" label="Filter 1" selected="selected" />

错误消息:未声明“selected”属性

我在< dropDown ... />中尝试了其他属性,如selectedItem,value和selected.声明,但似乎没有任何作用.

如果我只有正确的文档,这将是微不足道的,但即使是功能区自定义的完整Microsoft“文档”(找到here对此主题保持沉默.

我甚至试图查看位于http://schemas.microsoft.com/office/2006/01/customui的架构是否“人类可读”,但当我尝试在浏览器中打开它时,我被告知它不可用.也许有一招……

所以我转向这个论坛的综合智慧.从我的Q / A比率可以看出,我不经常这样做…

如何修改我的XML以便功能区打开,并在下拉控件中选择任意项?我会满足于它是第一项 – 但“我选择在我的XML中声明的任何项目”都会更好.

我正在为此寻找一个XML解决方案 – 宁愿不必添加onLoad VBA代码或其他VBA技巧.它有多难,对吧?……

看起来您需要使用VBA才能选择默认项目.

引自documentation for the dropDown element(我的重点):

getSelectedItemID (getSelectedItemID callback)

Specifies the name of a callback function to be called to determine the identifier of the item to be selected in this control. The getSelectedItemID and getSelectedItemIndex attributes are mutually exclusive. If neither attribute is specified,the control SHOULD NOT display a selected item. For example,consider the following XML fragment:

<gallery id="gallery" getItemCount="GetGalleryItemCount"  
   getItemID="GetItemID"
   getSelectedItemID="GetGallerySelectedItemID" />

In this example,the GetGallerySelectedItemID callback function is called when the application needs to determine the selected item in the gallery. In this example the callback function returns one of the identifiers returned by the GetItemID callback function. The possible values for this attribute are defined by the ST_Delegate simple type,as specified in section 2.3.2.

根据我对文档的阅读,您需要自己维护过滤器的当前所选项目. GetSelectedItemID处理程序将返回当前选定的项,OnAction处理程序将更新它.

在XML中:

<dropDown id="chooseFilter" showLabel="true" label="Filter"
   getSelectedItemID="GetSelectedItemID" onAction="OnAction"> 
   <item id="Filter1" label="Filter 1" /> 
   <item id="Filter2" label="Filter 2" />
</dropDown>

在您的工作簿的代码模块中:

Private mCurrentItemID As Variant

Sub GetSelectedItemID(control As IRibbonControl,ByRef itemID As Variant)
    If IsEmpty(mCurrentItemID) Then
        mCurrentItemID = "Filter1"
    End If
    itemID = mCurrentItemID
End Sub

Sub OnAction(control As IRibbonControl,selectedID As String,_
             selectedIndex As Integer)
    mCurrentItemID = selectedID
End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读