Add-in Express 2008 for Microsoft Office Snags

Add-in Express™ Support Service
That's what is more important than anything else

Add-in Express 2008 for Microsoft Office Snags
A few problems with Add-in Express 2008 for Microsoft Office 
Craig Watt




Posts: 8
Joined: 2008-03-17
Hi

I purchased Add-in Express 2008 for Microsoft Office on Friday and played around with it this weekend, where I encountered a few snags as follows. I am using VB in Visual Studio 2005 on Windows Server 2003:


Snag 1 - Adding Command Bar Buttons to Command Bar Popup is Slow and Erratic.

Using a Command Bar with UseForRibbon set to true in Word 2007, when adding Command Bar Buttons to a Command Bar Popup in code, there is a long delay between the code being run and the command bar buttons appearing. This delay seems to change each time the code is run, and sometimes the new buttons don't appear at all even though the code has run with no errors and it did iterate through the for each loop below. The button adding process also seems to be terribly slow. VB snippet, adds about 30 Command Bar Buttons from the click event of another Command Bar Button:


' Clear the classifications
Me.cbpuClassifications.Controls.Clear()

Dim tmpClass As Data.DataRow
Dim iCount As Integer = 0
For Each tmpClass In ds.Tables("category").Rows
iCount += 1
Dim newCommand As AddinExpress.MSO.ADXCommandBarButton = New AddinExpress.MSO.ADXCommandBarButton()
newCommand.ControlTag = Guid.NewGuid.ToString
newCommand.Caption = tmpClass.Item("category_Text")
newCommand.Tag = tmpClass.Item("classid")
newCommand.Visible = True
Me.cbpuClassifications.Controls.Add(newCommand)
Next


Snag 2 - You can use any .NET controls on your toolbars

I attempted to add a date picker control to a Command Bar using a Command Bar Advanced control and Tested it in Word 2000, but it did not display. Also, is there a way to achieve a similar thing in a Ribbon Bar for Word 2007, and if not are you planning on adding such functionality in a future release?


Snag 3 - Controls and code disappeared

While running through your Development Guide, suddenly all the controls in my Ribbon Bar disappeared and all the event procedures associated with them disappeared also even-though some of them also handled events from controls in my Command Bar. I am not 100% sure, but I think this happened after I relocated a control in the Ribbon Bar using a drag and drop operation.

Any tips would be much appreciated.

Regards
Craig

Posted 17 Mar, 2008 03:05:04 Top
Craig Watt




Posts: 8
Joined: 2008-03-17
Hi Again,

I also don't seem to be able to get event handlers for dynamically generated buttons in VB to work:

' Clear the classifications
Me.cbpuClassifications.Controls.Clear()

Dim tmpClass As Data.DataRow
Dim iCount As Integer = 0
For Each tmpClass In ds.Tables("category").Rows
iCount += 1
Dim newCommand As AddinExpress.MSO.ADXCommandBarButton = New AddinExpress.MSO.ADXCommandBarButton()
newCommand.ControlTag = Guid.NewGuid.ToString
newCommand.Caption = tmpClass.Item("category_Text")
newCommand.Tag = tmpClass.Item("classid")
newCommand.Visible = True
newCommand.Temporary = True
AddHandler newCommand.Click, AddressOf cbb_Click
Me.cbpuClassifications.Controls.Add(newCommand)
Next

Regards
Craig
Posted 17 Mar, 2008 03:40:46 Top
Craig Watt




Posts: 8
Joined: 2008-03-17
Hi Again,

OK, found your C# Add sample for adding controls dynamically and converted it to VB (below). The command controls are now being added immediately during the loop and their attached events are working, however, it is still taking about a second to add a single button, which is VERY slow, and even if I set the Temporary Flag to true the buttons remain when Word is re-started at which point they have also lost their link to the event procedures which no longer fire. Also they then cannot be cleared by a controls.clear directive.

To get around this I have added a controls.clear event to the Word.Quit event which works, but only if Word doesn't crash I suppose. Not a great workaround.

For those that are interested in the the VB solution to creating dynamic controls:

To Call:

Dim newCommand As AddinExpress.MSO.ADXCommandBarButton = Me.AddControl(me.cbpuClassifications, GetType(AddinExpress.MSO.ADXCommandBarButton), tmpClass.Item("category_Text"), Guid.NewGuid.ToString, 0, False, New AddinExpress.MSO.ADXClick_EventHandler(AddressOf cbb_Click), True)

Make sure you use the correct ADXnnnn_EventHandler object for you object.

The code:

Private Function AddControl(ByVal container As Object, ByVal ctrlType As Type, ByVal caption As String, ByVal controlTag As String, ByVal before As Integer, ByVal beginGroup As Boolean, _
ByVal eventHandler As Object, ByVal temporary As Boolean) As AddinExpress.MSO.ADXCommandBarControl

Dim adxNewControl As AddinExpress.MSO.ADXCommandBarControl = Nothing
Dim collection As AddinExpress.MSO.ADXBaseControlCollection = Nothing

If TypeOf container Is AddinExpress.MSO.ADXCommandBar Then
collection = TryCast(container, AddinExpress.MSO.ADXCommandBar).Controls
ElseIf TypeOf container Is AddinExpress.MSO.ADXCommandBarPopup Then
collection = TryCast(container, AddinExpress.MSO.ADXCommandBarPopup).Controls
End If

If collection Is Nothing Then
Return Nothing
End If

If eventHandler IsNot Nothing Then
adxNewControl = collection.GetControlByControlTag(controlTag, False)
If adxNewControl IsNot Nothing Then
Select Case ctrlType.Name
Case "ADXCommandBarButton"
AddHandler adxNewControl.AsButton.Click, TryCast(eventHandler, AddinExpress.MSO.ADXClick_EventHandler)
Exit Select
Case "ADXCommandBarComboBox"
AddHandler adxNewControl.AsComboBox.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
Exit Select
Case "ADXCommandBarDropDownList"
AddHandler adxNewControl.AsDropDownList.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
Exit Select
Case "ADXCommandBarEdit"
AddHandler adxNewControl.AsEdit.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
Exit Select
End Select
End If
End If

adxNewControl = collection.Add(ctrlType, controlTag, 1, before, temporary)
adxNewControl.BeginGroup = beginGroup
adxNewControl.Caption = caption
Select Case ctrlType.Name
Case "ADXCommandBarButton"
adxNewControl.AsButton.Style = AddinExpress.MSO.ADXMsoButtonStyle.adxMsoButtonCaption
'AddHandler adxNewControl.AsButton.Click, New AddinExpress.MSO.ADXClick_EventHandler(AddressOf cbb_Click)
If eventHandler IsNot Nothing Then
AddHandler adxNewControl.AsButton.Click, TryCast(eventHandler, AddinExpress.MSO.ADXClick_EventHandler)
End If
Exit Select
Case "ADXCommandBarComboBox"
If eventHandler IsNot Nothing Then
AddHandler adxNewControl.AsComboBox.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
End If
Exit Select
Case "ADXCommandBarDropDownList"
If eventHandler IsNot Nothing Then
AddHandler adxNewControl.AsDropDownList.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
End If
Exit Select
Case "ADXCommandBarEdit"
If eventHandler IsNot Nothing Then
AddHandler adxNewControl.AsEdit.Change, TryCast(eventHandler, AddinExpress.MSO.ADXChange_EventHandler)
End If
Exit Select
Case "ADXCommandBarPopup"
Exit Select
End Select
Return adxNewControl
End Function

Craig
Posted 17 Mar, 2008 05:15:46 Top
Craig Watt




Posts: 8
Joined: 2008-03-17
I have a drop down box in an ribbon bar group and I want to set it's width, how do I do that?
Posted 17 Mar, 2008 07:00:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7229
Joined: 2004-07-05
Hi Craig.

As you know Word stores all conrrols in the Normal.dot template.
If you change the Temporary property from False to True, you need to remove the remaining controls manually. Otherwise the changes will not be applied to your controls. As to the performance, Add-in Express uses the MS Office object model to add control. We can't speed up this process.

I have a drop down box in an ribbon bar group and I want to set it's width, how do I do that?

Please use the SizeString property of the ADXRibbonDropDown component.
Posted 17 Mar, 2008 11:13:58 Top
Craig Watt




Posts: 8
Joined: 2008-03-17
Hi Sergey,

Thanks for your reply, I will probably change the paradigm a little and use another mechanism more suited to the application where speed is an issue, there are lots of options there, so not a big deal.

I found the SizeString property after I posted the message, sorry I should have let you know...

Regards
Craig
Posted 18 Mar, 2008 10:07:01 Top