locked
Project 2010, VSTO Task Pane Problem RRS feed

  • Question

  • I created a very simple VSTO addin for Project 2010.  It only has 2 buttons - 1 on a Ribbon and another one a custom task pane.  Both buttons do the same thing - they filter "Outline Code1" for the value "PD.EE".

    Both buttons correctly filter the list of tasks.  However, after pressing the button on the task pane, you can't immediately scroll through the tasks with the mouse scroll wheel or the arrow keys.  When this happens, you have to click one of tasks first, then you can scroll. 

    Does anyone know why this happens with a button on a task pane?  Here is my code.

    Public Class ThisAddIn
    
        Private myFilterControl As UserControl1
        Private myCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane
        Public Shared myCustomTaskPaneCollection As Microsoft.Office.Tools.CustomTaskPaneCollection
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
    
            myFilterControl = New UserControl1
            myCustomTaskPaneCollection = Globals.Factory.CreateCustomTaskPaneCollection _
            (Nothing, Nothing, "CustomTaskPanes", "CustomTaskPanes", Me)
    
            myCustomTaskPane = myCustomTaskPaneCollection.Add(myFilterControl, "NeuroPMO")
            With myCustomTaskPane
                .DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft
                .Width = 150
                .Visible = True
            End With
    
        End Sub
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
            myCustomTaskPaneCollection.Dispose()
        End Sub
    
    End Class

    Ribbon1.vb

    Public Class Ribbon1
    
        Dim app As MSProject.Application
    
        Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
            app = Globals.ThisAddIn.Application
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
            app.SetAutoFilter(FieldName:="Outline Code1", FilterType:=MSProject.PjAutoFilterType.pjAutoFilterIn, Criteria1:="PD.EE")
        End Sub
    
    End Class

    UserControl1.vb

    Public Class UserControl1
    
        Dim app As MSProject.Application
    
        Private Sub UserControl1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            app = Globals.ThisAddIn.Application
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            app.SetAutoFilter(FieldName:="Outline Code1", FilterType:=MSProject.PjAutoFilterType.pjAutoFilterIn, Criteria1:="PD.EE")
        End Sub
    
    End Class
    .

    Wellyn

    Monday, February 11, 2013 8:56 PM

Answers

  • I got it!  I used Application.ActiveWindow.Activate.  Thanks for nudging me along.:)

    Wellyn

    Tuesday, February 12, 2013 2:50 PM

All replies

  • Do you have to click on a task or just anywhere in the view?

    Im thinking that your task pane has the 'focus' so the scroll wheel is trying to scroll there.

    Try adding this to your code at the end and see if that puts the scroll focus back on the top pane of the window

    application.ActiveWindow.TopPane.Activate


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Monday, February 11, 2013 9:29 PM
  • Brian,

    Thanks for the suggestion, but unfortunately it  didn't work.  In both cases, it looks like the Gantt Chart has the focus.  But you got me thinking about 'focus' and I think the MS Project application itself has lost the focus altogether.

    When I press the button from the ribbon (the one that works) the cell I was on originally (before pressing the button) is outlined in black.

    When I press the button from the task pane (the one that doesn't work) the cell I was on originally (before pressing the  button) is colored solid black.  This is also how it looks when I manually click on the Windows 7 toolbar, which is why I think the whole MS Project application has lost focus.  Does this make sense?

    Do you know the command for getting focus back to the application?


    Wellyn

    Tuesday, February 12, 2013 2:28 PM
  • I got it!  I used Application.ActiveWindow.Activate.  Thanks for nudging me along.:)

    Wellyn

    Tuesday, February 12, 2013 2:50 PM
  • Cool! did that work then?

    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Tuesday, February 12, 2013 4:01 PM
  • application.ActiveWindow.TopPane.Activate did not work, but application.ActiveWindow.Activate did.

    Wellyn

    Tuesday, February 12, 2013 4:23 PM
  • Great. I had a feeling it was a focus issue but did not think that it would be the whole app! :-)

    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Tuesday, February 12, 2013 4:24 PM