Changing button state

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

Changing button state
 
Pierre-D. Savard




Posts: 41
Joined: 2007-03-23
Hi, I read several post here to how changing a commandBar Button state. I write this code:
    Private Sub Track_Click(ByVal sender As System.Object) Handles toolTrack.Click
        If toolTrack.State = AddinExpress.VSTO.ADXMsoButtonState.adxMsoButtonUp Then
            toolTrack.State = AddinExpress.VSTO.ADXMsoButtonState.adxMsoButtonDown
        Else
            toolTrack.State = AddinExpress.VSTO.ADXMsoButtonState.adxMsoButtonUp
        End If

    End Sub


I got not error, but the button do not change state. If I trace in code, I see that the 'IF' work good, but at the line 'toolTrack.State = AddinExpress.VSTO.ADXMsoButtonState.adxMsoButtonDown' nothing change...

My button is a AdxCommandBar Button, initial state: adxMsoButtonDown, style = adxMsoButtonIconAndWrapCaption. All my toolbar are temporary set to false.

Another question in a OutlookItemEventsClass, how can I have a link to read the state property of the trak button on the current inspector to be able to do something if the state button are down?

Thanks again.
Posted 04 Apr, 2007 09:48:19 Top
Pierre-D. Savard




Posts: 41
Joined: 2007-03-23
In the same idea. In the ADXModule1.vb I have a function for the click on a toolbar button. I need to create a empty email and set the state of the commandbar button track of the inspector created for this email to down state. I try this, but I can't cast the Microsost.Office.Core.CommandBar into your ADXCommandBar. Can I use DirectCast or something like this?

Here is my code:

        Dim mail As Outlook.MailItem
        Dim MyInspector As Outlook.Inspector
        Dim Commandbar As New AddinExpress.VSTO.ADXCommandBar
        Dim CommandBarButton As New AddinExpress.VSTO.ADXCommandBarButton



        mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
        mail.Display()
        MyInspector = mail.GetInspector
        Commandbar = MyInspector.CommandBars
        CommandBarButton = Commandbar.Controls("toolTrack")
        CommandBarButton.State = AddinExpress.VSTO.ADXMsoButtonState.adxMsoButtonDown
Posted 04 Apr, 2007 10:20:47 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Pierre.

1. Thank you for the bug report. I will fix the issue in the next build.
Now you can use the following workaround:

Office.CommandBarButton btnObj =
adxCommandBarButton1.ControlObj as Office.CommandBarButton;

if (btnObj.State == Microsoft.Office.Core.MsoButtonState.msoButtonUp)
btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonDown;
else
btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonUp;

2. In OutlookItemEventsClass you can use the private variable of the Add-in Express control to get its current state. However, in this case you should have at least one opened inspector in Outlook.

3. As I have mentioned above, there is no need to cast the objects. You can use the actual variable of your button to change the State property.
However I would advise you to change the State of the button in the InspectorActivate event handler.


P.S. Note that we take up your forum requests in the order we receive them. Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 04 Apr, 2007 12:55:41 Top
Pierre-D. Savard




Posts: 41
Joined: 2007-03-23
Thanks for your help. I can see that you company made the right choice for supporting the developper. Each time I post here I got fast and reliable anwser! You did great job! Thank again

I have some question agin...

1- With your workaround i can change the state perfectly but I think i misundersand something. The inspector command bar I create in the design view are the same for all email (for example). If I change the state of one button, the state are the same for all other email that I will open. Is not the functionality I need. I need to have one toolbar for each email. In fact this toolbar display some information hidden in some user property of each email. The fonctionnality of clicking on a toolbutton are the same, but the state and text can be different. What is the best way to acheive this? Do I need to create dynamically the inspector commande bar in the inspector activate function and dispose it in the inspector close function?

2- I don't understand well the answer you priveded in the point 2. Do you talk about the variable passed in ref in the constructor: Public Sub New(ByVal ADXModule As AddinExpress.VSTO.ADXOutlookModule). I can create a private global variable in my OutlookItemEventsClass that will hold a reference of ADXModule? How can I found my command bar button from there?

thanks again
Posted 04 Apr, 2007 14:30:05 Top
Pierre-D. Savard




Posts: 41
Joined: 2007-03-23
Ok, I think I will auto answer the first one. I just to put my logic in the Inspector activate like this:
    Private Sub ADXModule1_InspectorActivate(ByVal sender As Object, ByVal inspector As Object, ByVal folderName As String) Handles Me.InspectorActivate
        Dim btnObj As Office.CommandBarButton

        If bCanConnect Then
            ItemEvents.ConnectTo(inspector.CurrentItem, True)

            Dim mail As Outlook.MailItem
            If inspector.CurrentItem.Class = Outlook.OlObjectClass.olMail Then
                mail = inspector.CurrentItem
                btnObj = toolTrack.ControlObj
                If mail.Subject.Contains("CRMFUZIONTAG:") Then
                    btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonDown
                Else
                    btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonUp
                End If
            End If
        End If
    End Sub


But I read that in the inspector Activate I must be carefull with the multi-explorer. What does it mean?
Posted 04 Apr, 2007 17:06:07 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Pierre.

1- With your workaround i can change the state perfectly but I think i misundersand something. The inspector command bar I create in the design view are the same for all email (for example). If I change the state of one button, the state are the same for all other email that I will open. Is not the functionality I need. I need to have one toolbar for each email. In fact this toolbar display some information hidden in some user property of each email. The fonctionnality of clicking on a toolbutton are the same, but the state and text can be different. What is the best way to acheive this? Do I need to create dynamically the inspector commande bar in the inspector activate function and dispose it in the inspector close function?

Unfortunately you can't change the state for a specific inspector. But you can synchronize the state for a specific inspector in the InspectorActivate event handler. Thus you can set an appropriate state for a button based on the active inspector.

2- I don't understand well the answer you priveded in the point 2. Do you talk about the variable passed in ref in the constructor: Public Sub New(ByVal ADXModule As AddinExpress.VSTO.ADXOutlookModule). I can create a private global variable in my OutlookItemEventsClass that will hold a reference of ADXModule? How can I found my command bar button from there?

Yes, you understood me correctly. All controls are accessible via private variables in the ADXModule class. You could create a new public property that returns an instance of you button to obtain its current state.

Ok, I think I will auto answer the first one. I just to put my logic in the Inspector activate like this:
Private Sub ADXModule1_InspectorActivate(ByVal sender As Object, ByVal inspector As Object, ByVal folderName As String) Handles Me.InspectorActivate
Dim btnObj As Office.CommandBarButton

If bCanConnect Then
ItemEvents.ConnectTo(inspector.CurrentItem, True)

Dim mail As Outlook.MailItem
If inspector.CurrentItem.Class = Outlook.OlObjectClass.olMail Then
mail = inspector.CurrentItem
btnObj = toolTrack.ControlObj
If mail.Subject.Contains("CRMFUZIONTAG:") Then
btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonDown
Else
btnObj.State = Microsoft.Office.Core.MsoButtonState.msoButtonUp
End If
End If
End If
End Sub

Yes, the code is correct.

But I read that in the inspector Activate I must be carefull with the multi-explorer. What does it mean?

You can always get the active explorer via the ActiveExplorer method of the Outlook application.
Posted 05 Apr, 2007 11:21:20 Top
Pierre-D. Savard




Posts: 41
Joined: 2007-03-23
Thanks Sergey,

I add this code in the Inspector Activate function


        If bCanConnect Then
            ItemEvents.ConnectTo(inspector.CurrentItem, True)

            If inspector.CurrentItem.Class = Outlook.OlObjectClass.olMail Then
                mail = inspector.CurrentItem
                If Not mail.Subject Is Nothing Then
                    btnObj = toolTrack.ControlObj
                    If mail.Subject.Contains("CRMFUZIONTAG:") Then
                        btnObj.Visible = False
                    Else
                        btnObj.Visible = True
                    End If
                End If
            End If
        End If


I add the test of the subjet is nothing to avoid error when this is a nre email.

But I don't know why, If I click on reply or on foward the Inspector Activate are called but i got en error on: btnObj.Visible = True because the the toolTrack.ControlObj return "nothing".
Idea?


2- I create a public Property in the ADXModule class that return the ControlObj of my commandbar button. In the OutlookItemEvents Class the constructor receive the ADXModule variable. But If in the class if I type ADXModule. I can't see my property. Where I do it wrong?

Posted 05 Apr, 2007 14:13:40 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Pierre.

1. I will send you a new build soon.
2. Is the ADXModule type or the name of the variable? Please check it.
Posted 06 Apr, 2007 08:41:15 Top