Putting a Value in a 2007 DropDown

E

Ed

Dabbling with ribbons.

I have properly created a new dropdown list in my customized Word2007
ribbon. It reads the contents of the folder when I have pointed it, and
(therefore) everything is listed when I drop the list down.

However, when the list initially displays (before dropping anything down),
it is blank, and except for a label that I could (but because of space
contraints, choose not to) add, no one would know what is in the list. How
can I cause the first item in the list to appear as the initial 'value' of
the list.

Probably related to the above: After I select an item from the list, I want
it to go back to the topmost item in the list. How can that be done? (It was
easy in 2003, seemingly impossible in 2007.)

Ed (in Virginia)
 
G

Greg Maxey

Ed,

Brings back nightmares of my own experience with something similiar. There
are still clumpls of hair and dreid scalp lying about my PC ;-)

Here is an abbreviated example of how I solved the issue:

First the XML script:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Main.Onload">
<ribbon>
<tabs>
<tab id="CustomTab" label="My Tab">
<group id="Grp1" label="My Group">
<dropDown id="DD1" showLabel="false"
getItemCount="Main.GetItemCount" getItemLabel="Main.GetItemLabel"
getSelectedItemIndex="Main.GetSelectedItemIndex" onAction="Main.MyDDMacro">
</dropDown>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Next the VBA:

Option Explicit
Public myRibbon As IRibbonUI
Private myArray() As String

Sub Onload(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub

Sub MyDDMacro(ByVal control As IRibbonControl, selectedId As String,
selectedIndex As Integer)
Select Case selectedIndex
Case 1
MsgBox "You clicked on" & selectedIndex
Case 2
MsgBox "You clicked on" & selectedIndex
Case 3
MsgBox "You clicked on" & selectedIndex
Case 4
MsgBox "You clicked on" & selectedIndex
End Select
'Force the control to repopulate
myRibbon.InvalidateControl control.id
End Sub

Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
'Always show first item when repopulating
Index = 0
End Sub

Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer, ByRef
label)
Select Case Index
Case Is = 0
label = "Select from list"
Case Else
label = myArray(Index)
End Select
End Sub

Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
Dim i As Long
count = 5
ReDim myArray(count - 1) As String
For i = 0 To UBound(myArray)
myArray(i) = "Label " & i
Next i
End Sub
 
E

Ed

Greg,

I would never have guessed that 'GetSelectedItemIndex' would handle what I
wanted. It worked like a charm. Thanks! (I pulled out just a little bit of
hair before resorting to the boards. I appreciate your being there.)

Ed (in Virginia)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top