DesignerControls.Find gets single instanc
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=1117
Printed Date: 12 December 2024 at 4:32am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: DesignerControls.Find gets single instanc
Posted By: dajv
Subject: DesignerControls.Find gets single instanc
Date Posted: 31 August 2004 at 1:59am
Gday,
I'm using Designer Studio to create my command bars menus, and have used multiple instances of controls. Some controls in the main menu of my application also appear in context menus.
To modify the control i get a control instance as in:
Dim Control as CommandBarControl
Set Control = CommandBars.DesignerControls.find(, MenuItemID, , True) |
and use the Control instance to change properties...
When I do this, it only affects one of the instances of the controls with id MenuItemID, so an item that appears in one of the main menus as well as a context menu only gets removed (using visible = false) in the main menu, and the instance in the context menu is not affected.
How do i get a reference to the other instances of the control (the one in the context menu)?
I want to avoid having a seperate control for each context menu item because this will add alot of controls and their operation is exactly the same as the instance in the main menu. When the control is removed from the main menu, i want that control also removed from the context menu (the behaviour i expected initially).
Any advice is appreciated.
Thanks
|
Replies:
Posted By: dajv
Date Posted: 31 August 2004 at 2:14am
I realised that I can Find() the controls inside the popup menu and set their properties.
Dim Popup As CommandBarPopup
Set Popup = CommandBars.DesignerControls.Find(, ID_CONTEXT_ITEM, , True)
Set Control = Popup.CommandBar.Controls.Find(, MenuItemID, , True) |
|
Posted By: dajv
Date Posted: 31 August 2004 at 9:46pm
Further to my above situation, I am having trouble getting a reference to toolbar buttons that also appear in the main menu.
Again, I want to avoid having a seperate control for the instance that will go in the toolbar.
I first tried using the below:
CommandBars.DesignerControls.Find(, IDR_STANDARDTEST, , True) |
(where IDR_STANDARDTEST is the id of the toolbar containing the controls) but this doesn't work (and after reading other posts, i discovered that top-level menus (in this case a toolbar) can't be accessed through the find() methods.
I then tried looping through the controls in the CommandBars.DesignerControls collection and couldn't find IDR_STANDARDTEST anywhere, nor could i find the controls that have hte toolbar as their parent, so it appears the method above i used for getting a reference to the controls used in the popup isnt going to work with the toolbar.
I examined the Control.Parent.BarID of the controls in the toolbar (a msgbox in the Execute() event) and noticed that the parent is IDR_STANDARDTEST, so they're there somewhere...
Must I resort to having unique controls for the toolbar?
Any advice is appreciated.
|
Posted By: SuperMario
Date Posted: 01 September 2004 at 6:41am
Top level controls can be accessed with the find method. You must
manually assign an Id to these controls. I.E (File, Edit, View,
Tools, etc... are generally top level controls that display other menu
items when clicked) .
The DesignerControls collection of
commands only holds commands that are displayed in the
"Commands" tab
of the Add\remove buttons customize dialog. This collection is
designed to hold all of your application's controls so the user can
add\remove them as needed. You need to manually add the controls
to the collection, and you should do this in the Customization
event. You are looking in the wrong place if you want to find a
control in the toolbar or menubar.
No, you do not need unique controls for the toolbar. Just make
sure that you manually assign an Id to any control that is a popup.
When searching, try something like this:
'Searches for the first occurence of Id in all commandbars starting with the menubar
Commandbars.Find(,ID,True)
'Searches for the first occurence of Id in the activemenubar
CommandBars.ActiveMenuBar(,ID,True)
'or CommandBars(1).Find(,ID,True)
'Searches for the first occurence of Id of a top level control in the activemenubar
CommandBars.ActiveMenuBar(,ID)
'Searches for the first occurence of Id in first toolbar
CommandBars(2).Find(,ID,True)
Hope this helps
|
Posted By: dajv
Date Posted: 01 September 2004 at 5:47pm
CommandBars(2).FindControl(, ID, , True) is just what i needed, thanks alot!
|
Posted By: Jens4
Date Posted: 07 December 2004 at 7:37am
I have nearly the same problem, one of my customers has made his own toolbar by the custom-dialog, he has added the same control twice….
I have a function that “check” the toolbar button, and in that function I use the FindContol, but I only give me the button……
The tow buttons have offcures the same ID, because the user just drags then same control to the same bar.
I know it is strange to have the same control on the same bar… but you know users….
|
Posted By: SuperMario
Date Posted: 07 December 2004 at 8:14am
Mabye use a "For each" to look through ALL your controls in each
command bar. FindControl will only find first occurance no matter
what.
But better yet, since the controls will have Id, you can set up a global variable used to indicate when
the control should be checked/unchecked, then in the CommandBars_Update
event you can use this variable to decide whether to check
the control.
'Global variable
Dim bCheckControl as Boolean
Private Sub CommandBars_Update(ByVal Control As XtremeCommandBars.ICommandBarControl)
On Error Resume Next
Select Case Control.Id
Case ID_APP_ABOUT: Control.Checked = bCheckControl
Case ID_FILE_NEW: Control.Checked = bCheckControl
End Select
End Sub
|
|