Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - FindControl property help - what type?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

FindControl property help - what type?

 Post Reply Post Reply
Author
Message
blockwood View Drop Down
Groupie
Groupie


Joined: 23 March 2004
Status: Offline
Points: 45
Post Options Post Options   Thanks (0) Thanks(0)   Quote blockwood Quote  Post ReplyReply Direct Link To This Post Topic: FindControl property help - what type?
    Posted: 07 April 2004 at 3:30pm
what is the proper code to find this control

Here is the code that builds this control: ID_RUN_LOAD_TABLES

    Set ControlRun = c.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Run", -1, False)
    With ControlRun.CommandBar.Controls
        .Add xtpControlButton, ID_RUN_LOAD_TABLES, "Load Tables", -1, False
        .Add xtpControlButton, ID_RUN_COMPARE, "Compare", -1, False
        .Add xtpControlButton, ID_RUN_STOP, "Stop", -1, False
        .Add xtpControlButton, ID_RUN_SHOW_LOAD_OPTIONS, "Object Compare Options", -1, False
    End With


this code returns nothing no matter what I do. I have experimented with different property types but nothing works. It is a file menu control

    Set cdjControl = CommandBars.FindControl(xtpBarTypePopup, ID_RUN_LOAD_TABLES)
    If Not cdjControl Is Nothing Then
        cdjControl.Enabled = False
    End If

it is a file menu control
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2004 at 3:49pm
Try this:

   Set cdjControl = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES,,True)
    If Not cdjControl Is Nothing Then
        cdjControl.Enabled = False
    End If

Edited by SuperMario
Back to Top
blockwood View Drop Down
Groupie
Groupie


Joined: 23 March 2004
Status: Offline
Points: 45
Post Options Post Options   Thanks (0) Thanks(0)   Quote blockwood Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2004 at 3:53pm
that did the trick. in under 5 minutes response time!
Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 12 May 2004 at 11:45pm

The method Find and FindControl is returned one control only.if  two controls uesed same Id,the second one is not returned.

Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 12 May 2004 at 11:53pm

The method Find and FindControl can not find top level menu.

Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 13 May 2004 at 6:00am
To find top level controls you must manually set an Id to those controls.

    Set ControlRun = c.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Run", -1, False)
    ControlRun.Id = ID_RUN
    With ControlRun.CommandBar.Controls
        .Add xtpControlButton, ID_RUN_LOAD_TABLES, "Load Tables", -1, False
        .Add xtpControlButton, ID_RUN_COMPARE, "Compare", -1, False
        .Add xtpControlButton, ID_RUN_STOP, "Stop", -1, False
        .Add xtpControlButton, ID_RUN_SHOW_LOAD_OPTIONS, "Object Compare Options", -1, False
    End With

And, Yes, only one control is returned with the find method.  You can just use a "for each" statement to look for them all, or search each command bar individually.
Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2004 at 2:16am

Thanks for SuperMario help!

"for each" is very good.

 

Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2004 at 2:56am

I finding the control for set the Enbaled and the Visible.

I want do it like this:

Commandbars.ActiveMenuBar.Controls(ID_RUN_LOAD_TABLES).Enabl ed=TRUE

Commandbars.ActiveMenuBar.Controls(ID_RUN_LOAD_TABLES).Visib le=TRUE

Reference ActiveBar please.

Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2004 at 6:49am
'When you create the control, you must manually set the Id property if this is a top level control like this:

Dim ControlRun as CommandbarControl

Set ControlRun = CommandBars.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Edit", -1, False)
ControlRun.Id = ID_RUN_LOAD_TABLES

'Then in your execute event you can add something like this to find the control and enable/disable.
Set Control = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES , True)
If Not Control Is Nothing Then
      Control.Enabled = False
End If

When controls are added to a commandbar such as the active menubar,  they can be referenced by the index, which is assigned by the order that the controls were added starting at 1.

So you would need to use the index of the control if you are referencing it directly, for example:
     CommandBars.ActiveMenuBar.Controls(2).Enabled = False
This line of code disabled the second control in the active menubar.  You can use the index of a control once you find it.

Set Control = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES , True)
If Not Control Is Nothing Then
     CommandBars.ActiveMenuBar.Controls(Control.Index).Enabled = False
End If

Hope this helps.


Edited by SuperMario
Back to Top
blockwood View Drop Down
Groupie
Groupie


Joined: 23 March 2004
Status: Offline
Points: 45
Post Options Post Options   Thanks (0) Thanks(0)   Quote blockwood Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2004 at 8:54am
"And, Yes, only one control is returned with the find method. You can just use a "for each" statement to look for them all, or search each command bar individually."

Can you show how to do this? The common task to is enable a File Menu Item AND a toolbar button with the same ID (as often they are shown in menu AND toolbar) to do this I use the following. One block of code seems to work for toolbars and the other seems to work for Menus but it sounds as if there is a better way to do it.

This code is used to Show/Hide certain controls

Public Function ShowCodeJockControl(c As CommandBars, id As Long, bolOn As Boolean)
Dim Control As CommandBarControl

    '   For toolbar
    Set Control = c.FindControl(, id, , True)
    If Not Control Is Nothing Then
        Control.Visible = bolOn
    End If
    
    '   For File Menu
    Set Control = c.ActiveMenuBar.FindControl(, id, , True)
    If Not Control Is Nothing Then
        Control.Visible = bolOn
    End If
End Function
Back to Top
blockwood View Drop Down
Groupie
Groupie


Joined: 23 March 2004
Status: Offline
Points: 45
Post Options Post Options   Thanks (0) Thanks(0)   Quote blockwood Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2004 at 8:37pm
i never got reply to my last question
Back to Top
skluc View Drop Down
Newbie
Newbie
Avatar

Joined: 19 May 2004
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote skluc Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2004 at 3:15am

I also wait for an answer to the question by blockwood.

How use the for each to navigate the commandbar?

The solution by blockwood is good for a tool thati is in the activebar and in ONE toolbar.

But if the same tool is in more toolbar?

Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2004 at 7:22am

I was sovled this problem by my code.

Back to Top
skluc View Drop Down
Newbie
Newbie
Avatar

Joined: 19 May 2004
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote skluc Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2004 at 7:38am
where can we see your code?
Back to Top
asd123456789 View Drop Down
Newbie
Newbie


Joined: 12 May 2004
Location: China
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote asd123456789 Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2004 at 6:57pm

1:Create a list to hold all ID and controls added.

2:Seek the list by ID to found controls one by one.

3:Set Property of controls found.

 

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.