Dynamic Command Bar Buttons

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

Dynamic Command Bar Buttons
 
Minhaj Khan




Posts: 15
Joined: 2006-08-17
Hi

I had an adxCommandBar that is inserted into main outlook menu. The structure goes as such ...

DK - ADXCOmmandBarPopup

File - ADXCOmmandBarPopup
Open ... - ADXCommandBarButton
New ... - ADXCommandBarButton
Save AS ... - ADXCommandBarButton (BeginGroup=True)
------------------------------------------------------
Connections ... - ADXCommandBarButton (BeginGroup=True)
------------------------------------------------------
< :?: :?: :?: >

<At this point, I am interested in appending some data-driven contextual ADXCommandBarButtons dynamically at run-time, but failed to find control collection for my customly design time added adxCommandBar. Say mbrDK in this case with tag property set to mbrDK as well>

So to questions line

1. How can new ADXCommandBarButtons be append on the fly to an already design time generated ADXCommandBar?
2. How can the ADXCommandBarButtons as well as ADXCOmmandBarPopups be either enabled/disabled or visibled/invisibled?
3. Can the same technique be applied to custom toolbars?

Hope that help.
Thanks in advance for your consideration and time.
Posted 28 Sep, 2006 01:36:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Minhaj.

1. Please download the following example:
http://www.add-in-express.com/projects/oldynamiccontrolsexample-vs2005.zip
2. To enable/disable command bars - use the Enable property of the ADXCommandBar, ADXOlExplorerCommandBar, ADXOlInspectorCommandBar components, to hide/show command bars - the Visible property of the same components.
3. The best way is to add a custom command bar at the desigh time and then you can hide/show it at the runtime.
(the example here: http://www.add-in-express.com/projects/oldyncommandbars.zip)
Posted 28 Sep, 2006 11:01:37 Top
Minhaj Khan




Posts: 15
Joined: 2006-08-17

Thanks Sergey but that exactly not what I was looking for.

In examples projs. you had used to create command bar on the fly every time while mine case is different. I dont want to flicker menus each time rather our aim is to add/remove command bar buttons dynamically, NOT entire bar. Also note that command bar has been created using design time.

Let me relate back

DK - File - Open ...
DK - File - New ...
DK - File - Save AS ...
DK - File - Seperator (-)
DK - File - My Dynamic Command Bar Button

Suppose we want to display text "My Orders" based on certain option ticked on by the end-user so that a certain form will be displayed upon clicking this newly dynamically generated command bar button.

How to add/remove dynamically generated command bar buttons to a command bar that has been created at design time?

Hope that clarifies and make understandable.
Thanks again for your time and consideration.
Posted 04 Oct, 2006 00:45:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Minhaj.

In the code I don't create the command bar every time. I connect to the command bar if it already exists in the addinmodule (see the source code of the CommandBarAdd method in the ADX installation package).
You can create the 'My Dynamic Bar' at the design time if you wish.
It's up to you.
Posted 04 Oct, 2006 17:28:37 Top
Minhaj Khan




Posts: 15
Joined: 2006-08-17

Sergey,

Considering "My Dynamic Bar" has been created at desing time with nested hierarchy like Popup1 -> Popup2 -> Popup3 -> Button1. How can I search for "Button1"? I had tried with GetControlByControlTag, FindCommandBarObj and FindControlObj, but unfortunately I always got either a null or Button1 not connected prompts. Simillarly once found, need to toggle visibiity depending upon certain condition.

Anyhow, thanks for correcting me.
Posted 04 Oct, 2006 23:46:50 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Minhaj, if you can't find the button, it means that the parameters you use are incorrect. Usually all inspector command bars/controls are connected in the InspectorActivate event handler. Please use this event to find/modify dynamically added buttons.
Posted 05 Oct, 2006 09:28:41 Top
Minhaj Khan




Posts: 15
Joined: 2006-08-17

Sergey,

Fortunately the button was found using proper parameter. The problem comes in picture when I tried to add a new button to Popup3 at runtime. The following line of code throws an exception stating the add-in is not connected.
adxNewControl = collection.Add(ctrlType, controlTag, 1, before, temporary);

Although the collection contains all design-time generated buttons. Any idea on how to add new buttons on the fly? An example would be much appreciated.

Posted 05 Oct, 2006 23:44:59 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Minhaj, doesn't the 'oldynamiccontrolsexample-vs2005' example suit you?
If so, please tell me about your requirements and I will develop another example for you.
Posted 06 Oct, 2006 07:38:08 Top