problems with removehandler from outlook.folder.items.itemadd RRS feed

  • Question

  • Hey there,

    I've had written some nice stuff but due to some mistake everything was lost again, so we try to make it nice again.
    I'm new here so i hope its posted in the correct forum and correct style.

    I'm developing an Outlook add-in atm with VSTO in VB (vs2008 if it helps).
    In the process to it, i succesfully worked with add and removehandler and stuff like that.
    But atm i'm stuck with the handlers from the outlook.folder.items.itemadd.

    The dynamic assinging of the addhandler works fine, but when i want to delete the handler from the object then i get the error.

    addhandlers and removehandlers from buttons i tried the same way and work, but not on the folder item.

    here some code snippet what i want to accomplise:

    Dim folderObject As Microsoft.Office.Interop.Outlook.Folder 
    Public Sub AddFolderWatchHandlers() 
        folderObject = GetFolder(folderUniqueArray(0)) 
        AddHandler folderObject.Items.ItemAdd, AddressOf items_add 
    End Sub
    Public Sub DeleteFolderWatchHandlers() 
      RemoveHandler folderObject.Items.ItemAdd, AddressOf items_add 
    End Sub
    Public Sub items_add(ByVal item As System.Object) 
    End Sub

    Where GetFolder returns a folder object from the name given from the folderUniqueArray (Just the first items to test with)

    Now when i add the event, it works, and it works fine.
    But the intension is to make it dynamicly so that the array can be looped to add the handers to more folders if needed
    (that also works fine btw)
    But when the list gets shorter, aka a folder gets removed from that list i want to delete the handler from that object.
    thats where i call the deletehandeler.

    There is where the error code starts,
    the error is a nullpointer, while i added the object there,
    trouble shooting tips (first one) gives: use the 'new' keyword to create an object instance

    any headsup would be realy appreciated


    Thursday, May 27, 2010 3:40 PM