Show/Hide ADXForm on ExplorerSelectionChange

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

Show/Hide ADXForm on ExplorerSelectionChange
Lance Friedemann

Posts: 24
Joined: 2017-02-10
I have learned that the BeforeFormShow event is called with each new Inspector window, however it is only called once when the Explorer (or reading pane) is opened the first time and never again. I want to call the BeforeFormShow event in the ADXForm with each new AdxOutlookAppEvents.ExplorerSelectionChange. How can I accomplish this?

In the AddinModule I have:

    Private Sub adxOutlookEvents_ExplorerSelectionChange(ByVal sender As System.Object, ByVal explorer As System.Object) Handles AdxOutlookAppEvents1.ExplorerSelectionChange

        Debug.Print("The ExplorerSelectionChange event has occurred.")
        Dim theExplorer As Outlook.Explorer = TryCast(explorer, Outlook.Explorer)
        If theExplorer IsNot Nothing Then
            Dim selection As Outlook.Selection = Nothing
                selection = theExplorer.Selection
            End Try

            If selection IsNot Nothing Then
            End If
        End If
        GloMsgID = GetEmailHeader()

        If GloMsgID.Contains("Foo") Then
            '*** 'This should call ADXOlForm.BeforeFormShow for the Explorer window. I cannot find a method to fire the form to close, open or update for each new selection in the Explorer. I need to hide/show the form based on criteria. 
        End If

    End Sub

    Private Function GetEmailHeader() As String
        Dim explorer As Outlook._Explorer = Nothing
        Dim selection As Outlook.Selection = Nothing
        Dim mailItem As Outlook._MailItem
        Dim item As Object = Nothing
        Dim headerText As String = String.Empty

            explorer = OutlookApp.ActiveExplorer()
            'Explorer.Selection fires an exception for a top-level folder  
            selection = explorer.Selection
            item = selection.Item(1)
            If TypeOf item Is Outlook._MailItem Then
                mailItem = CType(item, Outlook._MailItem)

                If Me.HostMajorVersion >= 12 Then ' Outlook 2007 and higher
                    ' use late binding
                    Dim propertyAccessor As Object = Nothing
                    propertyAccessor = mailItem.GetType().InvokeMember( _
                        "PropertyAccessor", Reflection.BindingFlags.GetProperty, Nothing, mailItem, New Object() {})
                    headerText = propertyAccessor.GetType().InvokeMember( _
                        "GetProperty", Reflection.BindingFlags.InvokeMethod, Nothing, propertyAccessor, _
                        New Object() {""}).ToString()
                End If
            End If
            If explorer IsNot Nothing Then Marshal.ReleaseComObject(explorer)
            If selection IsNot Nothing Then Marshal.ReleaseComObject(selection)
            If item IsNot Nothing Then Marshal.ReleaseComObject(item)
        End Try

        Return headerText

    End Function

Posted 20 Mar, 2017 00:35:31 Top
Andrei Smolin

Add-in Express team

Posts: 15595
Joined: 2006-05-11
Hello Lance,

Lance Friedemann writes:
I want to call the BeforeFormShow event in the ADXForm with each new AdxOutlookAppEvents.ExplorerSelectionChange. How can I accomplish this?

The forms manager only create a form instance once: before the form instance is embedded in an Outlook window (inspector or explorer). On the other hand, the ADXBeforeFormShow event is fired before the form is shown. That is, if the form is hidden via ADXOlForm.Hide() and you call ADXOlForm.Show, you'll get the ADXBeforeFormShow event.

Could you please explain what you need to achieve?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Mar, 2017 04:15:53 Top