Loading task panes from another assembly

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

Loading task panes from another assembly
 
Sumit Talati


Guest


Hi,

For an Excel COM addin, is it possible for ADXExcelTaskPanesCollectionItem.TaskPaneClassName to refer to a type which is in another assembly? Is there any other way in which we can achieve the same outcome? For example, having a "container" task pane type in the addin assembly, and a custom control in another assembly, with the custom controls being added to the container task pane at runtime? I tried the following code in the event handler for AddinInitialize, but the label does not appear.


var item = new AddinExpress.XL.ADXExcelTaskPanesCollectionItem(this.components)
{
    TaskPaneClassName = typeof(OtherAssembly.TaskPaneMock).FullName,
    Position = AddinExpress.XL.ADXExcelTaskPanePosition.Right
};

taskPanesManager.Items.Add(item);

item.TaskPaneInstance.Controls.Add(new System.Windows.Forms.Label() 
{ Name = "lblDynamic", Text = "dynamic", BackColor = System.Drawing.Color.Aqua, Dock = System.Windows.Forms.DockStyle.Fill });
item.ShowTaskPane();



Note that the task pane itself has just one button in the center which appears in Excel.

Thanks

Sumit
Posted 27 Sep, 2010 11:50:25 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hi Sumit,

No, taskPanesManager cannot create a task pane defined in another assembly. Note that you can call a method defined in the other add-in; the method could display the task pane.

ExcelApp.COMAddins.Item(strMyComAddinProgId).Object.MyPublicPropertyOrMethod.

1. strMyComAddinProgId - see the ProgId attribute of your add-in module.
2. MyPublicPropertyOrMethod is called via late binding (see System.Type.InvokeMember in MSDN or search this forum)

Also, please pay attention to http://www.add-in-express.com/creating-addins-blog/2010/03/24/addin-xll-rtd-one-assembly/; it deals with the situation when several Office extensions are located in the same assembly.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Sep, 2010 12:10:16 Top
Sumit Talati


Guest


Hi Andre,

Many thanks for you quick response.

I think I did not explain my problem very clearly. There is only one addin module and when that module initializes it loads up the required functionality from other plain .NET assemblies (not addins).
These other assemblies provide different bits of functionality and it is far more easier for us to maintain when the code is structured across assemblies rather than just one massive assembly.

Is there another way of loading up task panes which reside in a different assembly but inheriting from ADXExcelTaskPane?

Is there a reason why controls added after the instance is created do not show up in the task pane? (see first post for code)


Regards

Sumit
Posted 28 Sep, 2010 04:25:38 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hi Sumit,

Sumit Talati wrote:
For example, having a "container" task pane type in the addin assembly, and a custom control in another assembly, with the custom controls being added to the container task pane at runtime


I believe there is no problem to implement that scheme. The only requirement is: the container task pane must be located in the add-in assembly. This resembles using a third-party control in your project, doesn't it?


Andrei Smolin
Add-in Express Team Leader
Posted 28 Sep, 2010 09:23:51 Top
Sumit Talati


Guest


Hi Andre,

Thanks for confirming it should work. You are correct that the idea is to have it behave as if it was using a third party control. I have managed to get it to work by doing the following:


if (item.TaskPaneInstance == null)
   item.CreateTaskPaneInstance();
item.TaskPaneInstance.Controls.Add(userControl);


Is this the correct way of doing it?

Thanks

Sumit
Posted 28 Sep, 2010 09:31:35 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hi Sumit,

This is one of correct ways of doing this. :)


Andrei Smolin
Add-in Express Team Leader
Posted 28 Sep, 2010 10:00:07 Top
Sumit Talati


Guest


Hi Andrei,

Thanks for the confirmation. I will take this approach.

Regards

Sumit
Posted 28 Sep, 2010 10:08:12 Top