Manipulate controls on a Task Pane from another Task Pane

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

Manipulate controls on a Task Pane from another Task Pane
Kirill Lapin

Posts: 42
Joined: 2011-05-04
Hi there,

I can now get hold of the current instance of a pane from the AddinModule :) How can I grab ADXExcelTaskPane2 instance object from, say, the ADXExcelTaskPane1 class please? I tried to define a global variable in the Globals module:
    Public ShowTaskPane1 As Boolean
    Public ShowTaskPane2 As Boolean
    Public ShowTaskPane3 As Boolean
    Public CurrentTaskPane1Instance As ADXExcelTaskPane1
    Public CurrentTaskPane2Instance As ADXExcelTaskPane2
    Public CurrentTaskPane3Instance As ADXExcelTaskPane3

In the AddinModule:
    Private Sub AddinModule_OnTaskPaneAfterCreate(sender As Object, instance As ADXTaskPane.ADXCustomTaskPaneInstance, control As Object) Handles Me.OnTaskPaneAfterCreate
        CurrentTaskPane1Instance = AdxExcelTaskPanesCollectionItem1.TaskPaneInstance
        CurrentTaskPane2Instance = AdxExcelTaskPanesCollectionItem2.TaskPaneInstance
        CurrentTaskPane3Instance = AdxExcelTaskPanesCollectionItem3.TaskPaneInstance
    End Sub

And then tried the following from the ADXExcelTaskPane1 module:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ShowTaskPane2 = True
        CurrentTaskPane2Instance.Visible = ShowTaskPane2    End Sub

But no joy. What am I doing wrong please?.

I am getting the 'System.NullReferenceException' at the second line of the button click event, which probably means that CurrentTaskPane2Instance is Nothing.

Posted 24 Dec, 2018 10:14:49 Top
Kirill Lapin

Posts: 42
Joined: 2011-05-04
My current work around is to create a public function in the AddinModule that returns TaskPane object:
    Public Function GetTaskPane1() As ADXExcelTaskPane1
        Return TryCast(Me.AdxExcelTaskPanesCollectionItem1.TaskPaneInstance, ADXExcelTaskPane1)
    End Function

    Public Function GetTaskPane2() As ADXExcelTaskPane2
        Return TryCast(Me.AdxExcelTaskPanesCollectionItem2.TaskPaneInstance, ADXExcelTaskPane2)
    End Function

    Public Function GetTaskPane3() As ADXExcelTaskPane3
        Return TryCast(Me.AdxExcelTaskPanesCollectionItem3.TaskPaneInstance, ADXExcelTaskPane3)
    End Function

and use it as follows from say ADXExcelTaskPane3 module:
    Dim taskPane2 As ADXExcelTaskPane2 = AddinModule.GetTaskPane2
    taskPane2.TreeView1.SelectedNode = Nothing

This works, but I am not sure if the object is already exposed by default. I can't find any property or method in the ADX generated code.

Posted 25 Dec, 2018 07:01:35 Top
Dmitry Kostochko

Add-in Express team

Posts: 2841
Joined: 2004-04-05
Hi Kirill,

Your code looks correct. There exists another solution, you can use the CurrentInstance property of your add-in module, for example:

Dim item1 As ADXExcelTaskPanesCollectionItem =

Dim item2 As ADXExcelTaskPanesCollectionItem =

Dim item3 As ADXExcelTaskPanesCollectionItem =

Note, you need to specify the namespace of your project (MyAddin22 in my case) to get access to the AddinModule shared properties.
Posted 26 Dec, 2018 04:28:38 Top