Communication between add-in components

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

Communication between add-in components
is there a better (more appropriate) way to do this? 
Michael Gatzonis


Guest


I have a Add-on which declares a Module, a Toolbar and a Sidebar as
MyNamespace.MyModule
MyNamespace.MySideBar with name adxieBarItem1
MyNameSpace.MyToolbar with name adxieToolBarItem1

I want to change a sidebar's control property (e.g. textbox1) when a button (e.g.Button1) on MyToolbar is clicked.
Here is the code I use (C#). Although this works I wonder if there is a better way to do it.

1. MyToolbar Code

private void onButton1_Click(object sender, EventArgs e)
{
MyNameSpace.MyModule theModule = (MyNameSpace.MyModule) this.Module;
for (int i = 0; i <= theModule.GetModuleCount() - 1; i++)
{
MyNameSpace.MyModule aModule = (MyNameSpace.MyModule) theModule.GetModuleByIndex(i);
if (aModule.IsTabActive()) //find active tab
{
aModule.ChangeProperty(newValue); //Call a public method of MyModule
}
}
}

2. MyModule Code

public void ChangeProperty(String newValue)
{
MyNameSpace.MySideBar mybar = (MyNameSpace.MySideBar) adxieBarItem1.BarObj;
if (mybar != null) //Check if sidebar is loaded
{
mybar.ChangeProperty(newValue); //call a public method of MySideBar
}
}

3. MySideBar Code
public void ChangeProperty(String newValue)
{
textbox1.text = newValue;
}


Thanks
Michael
Posted 28 Jan, 2010 10:12:00 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hi Michael,

Try the following:

1. MyToolbar Code

     private void onButton1_Click(object sender, EventArgs e)
     {	
	 MyNameSpace.MyModule theModule = (MyNameSpace.MyModule) this.Module;             
                 theModule.ChangeProperty(newValue);     //Call a public method of MyModule
     }



Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2010 11:26:07 Top