Print Page | Close Window

FindControl property help - what type?

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=607
Printed Date: 27 November 2024 at 4:44am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: FindControl property help - what type?
Posted By: blockwood
Subject: FindControl property help - what type?
Date 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



Replies:
Posted By: SuperMario
Date 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


Posted By: blockwood
Date Posted: 07 April 2004 at 3:53pm
that did the trick. in under 5 minutes response time!


Posted By: asd123456789
Date 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.



Posted By: asd123456789
Date Posted: 12 May 2004 at 11:53pm

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



Posted By: SuperMario
Date 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.


Posted By: asd123456789
Date Posted: 14 May 2004 at 2:16am

Thanks for SuperMario help!

"for each" is very good.

 



Posted By: asd123456789
Date 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.



Posted By: SuperMario
Date 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.


Posted By: blockwood
Date 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


Posted By: blockwood
Date Posted: 19 May 2004 at 8:37pm
i never got reply to my last question


Posted By: skluc
Date 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?



Posted By: asd123456789
Date Posted: 20 May 2004 at 7:22am

I was sovled this problem by my code.



Posted By: skluc
Date Posted: 20 May 2004 at 7:38am
where can we see your code?


Posted By: asd123456789
Date 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.

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net