如何在Excel自定义功能区控件的下拉式控件中设置默认值 [英] How to set default value in dropdown control for Excel custom ribbon control

查看:1960
本文介绍了如何在Excel自定义功能区控件的下拉式控件中设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Excel 2010创建了一个自定义的Fluent Ribbon界面,其中包含一个下拉列表。相关的XML代码(简化):

I have created a custom Fluent Ribbon interface for Excel 2010 which includes a dropdown. Relevant XML code (simplified):

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

加载功能区时,不会选择任何值 - 下拉列表看起来为空。

When the ribbon is loaded, no value is selected - the dropdown looks empty.

我希望默认选择第一个项目 - 但找不到任何描述如何做的文档。我查看了 MSDN文档,控制但并没有涵盖这种情况。我尝试过HTML样语句的各种排列,但是它们都被自定义UI编辑器拒绝。我试过的例子:

I would like the first item to be selected by default - but could not find any documentation describing how to do it. I looked at the MSDN documentation for the control but it did not cover this case. I tried various permutations of "HTML-like" statements, but they were all rejected by the custom UI editor as invalid. Examples of the things I tried:

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

错误消息:'selected'属性未声明为

我尝试过其他属性,如 selectedItem value 选择在< dropDown ... /> 声明中,但似乎没有任何效果。

I tried other attributes like selectedItem, value, and selected in the <dropDown .../> declaraction, but nothing seemed to work.

如果只有我有正确的文档,这将是微不足道的,但即使是完整的Microsoft文档的功能区自定义(发现这里没有提到这个问题。

If only I had the right bit of documentation this would be trivial, but even the full Microsoft "documentation" for the Ribbon customization (found here was silent on the subject.

我甚至试图看看架构是否位于< a href =ht tp://schemas.microsoft.com/office/2006/01/customuirel =nofollow noreferrer> http://schemas.microsoft.com/office/2006/01/customui 可能是人可读,但是当我试图在浏览器中打开它时,我被告知它不可用。也许有一个窍门...

I even tried to see if the schema located at http://schemas.microsoft.com/office/2006/01/customui might be "human readable", but when I tried to open it in the browser, I was told it was unavailable. Maybe there is a trick...

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

So I turn to the combined wisdom of this forum. You can see from my Q/A ratio that I don't do this very often...

如何修改我的XML,使功能区打开一个任意的在下拉菜单中选择的项目?我会认为它是第一个项目 - 但我选择在我的XML中声明的任何项目将是更可取的。

How do I modify my XML so that the ribbon opens with an arbitrary item selected in the drop-down control? I will settle for it being the first item - but "any item I choose to declare in my XML" would be preferable.

我正在寻找一个XML解决方案 - 不想添加 onLoad VBA代码或其他VBA技巧。它是多么难,对...?

I am looking for an XML solution for this - would prefer not to have to add onLoad VBA code or other VBA trick. How hard can it be, right?...

推荐答案

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

It looks like you need to use VBA in order to select a default item.

dropDown元素的文档(我的重点):


getSelectedItemID(getSelectedItemID callback)

getSelectedItemID (getSelectedItemID callback)

指定要调用的回调函数的名称,以确定在此控件中要选择的项目的标识符。 getSelectedItemID和getSelectedItemIndex属性是互斥的。 如果没有指定属性,则控件不应显示所选项。例如,考虑以下XML片段:

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" />




在此示例中,GetGallerySelectedItemID回调函数在应用程序需要时调用确定画廊中选定的项目。在这个例子中,回调函数返回GetItemID回调函数返回的一个标识符。此属性的可能值由ST_Delegate简单类型定义,如第2.3.2节所述。

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处理程序将更新它。

According to my reading of the documentation, you're expected to maintain the current selected item of the filter yourself. The GetSelectedItemID handler will return the currently selected item and the OnAction handler will update it.

在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>

在工作簿的代码模块中:

And in a code module of your workbook:

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

这篇关于如何在Excel自定义功能区控件的下拉式控件中设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆