SelectionChange only fires once

I am trying to run some logic as a user selects different folders in Outlook (e.g. - Inbox to a subfolder to another subfolder, etc.) I want to enable / dusable some commandbuttons, etc. The problem is that the event fires once and no more.

What is the best event to handle for this purpose Is it SelectionChange

Why would the event stop firing WHat could I have done wrong in my code

 



Answer this question

SelectionChange only fires once

  • Lars XLN Audio

    Sounds a lot like "My button stopped working" problem as described here.

    You need to make sure the object exposing the SelectionChange event is not a local variable inside your method. It is just getting Garbage Collected and you stop getting the event.



  • martinsd

    Misha is correct that this is a problem we have found before. You may also wish to take a look at our Outlook samples as they use the CommandBar OM to do the very type of thing you are attempting to do:

    For example, in my tasks article, I have a global declaration for a custom menu item called _exportTasks. I use the FolderSwitch event, and in there I compare the ID for the folder to which the user has switched. If that ID matches the ID of the target folder, I enable the menu:

        Private Sub _Explorer_FolderSwitch() _
        Handles _Explorer.FolderSwitch
            If _Explorer.CurrentFolder.EntryID = _
            _mapiTasks.EntryID Then
                _exportTasks.Enabled = False
            Else
                _exportTasks.Enabled = True
            End If
        End Sub

    Stay up to date on the VSTO 2005 Outlook content, examples, downloads, etc. by visiting the resources list here:
    http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx

    HTH

    John.



  • SelectionChange only fires once