Print Page | Close Window

Trouble with xtpControlRadioButton

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=8356
Printed Date: 18 October 2024 at 4:37am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Trouble with xtpControlRadioButton
Posted By: clubside
Subject: Trouble with xtpControlRadioButton
Date Posted: 09 October 2007 at 5:32am
Howdy,
 
I'm trying to implement a RadioControl list in a pop-up menu (the sad fact is that I can implement it fine as a ComboBox in the Ribbon, but its companion object, which I implemented as a pop-up Treeview, would not render properly and there is no companion Event to InitCommandsPopup so I had to switch to doing it on a menu) but since CommandBars will not manage the state itself I'm trying to unsuccessfully. All I'm trying to do it make the items works like a radio control, so only the newly selected item is "checked", but FindControl is failing.
 
Here is how the menu is built:
 
    Set ControlPopup = ControlOptions.CommandBar.Controls.Add(xtpControlPopup, ID_SVR_SOURCE, "Source Server", -1, False)
    Set Control = ControlPopup.CommandBar.Controls.Add(xtpControlRadioButton, ID_SVR_SOURCE_CONTENT, "Content Editor", -1, False)
    Control.Checked = True
    Set Control = ControlPopup.CommandBar.Controls.Add(xtpControlRadioButton, ID_SVR_SOURCE_NS1, "NS1", -1, False)
    Control.BeginGroup = True
    ControlPopup.CommandBar.Controls.Add xtpControlRadioButton, ID_SVR_SOURCE_TESTPAK, "TestPak", -1, False
    ControlPopup.CommandBar.Controls.Add xtpControlRadioButton, ID_SVR_SOURCE_TRYSTARS, "TryStars", -1, False
    ControlPopup.CommandBar.Controls.Add xtpControlRadioButton, ID_SVR_SOURCE_SUPPORT, "Support", -1, False
Here is the code inside the Execute event:
 
        Case ID_SVR_SOURCE_CONTENT, ID_SVR_SOURCE_NS1, ID_SVR_SOURCE_TESTPAK, ID_SVR_SOURCE_TRYSTARS, ID_SVR_SOURCE_SUPPORT
            Set FoundControl = CommandBars.FindControl(, ID_SVR_SOURCE_CONTENT)
            If Not FoundControl Is Nothing Then
                FoundControl.Checked = False
            End If
            Set FoundControl = CommandBars.FindControl(, ID_SVR_SOURCE_NS1)
            If Not FoundControl Is Nothing Then
                FoundControl.Checked = False
            End If
            Set FoundControl = CommandBars.FindControl(, ID_SVR_SOURCE_TESTPAK)
            If Not FoundControl Is Nothing Then
                FoundControl.Checked = False
            End If
            Set FoundControl = CommandBars.FindControl(, ID_SVR_SOURCE_TRYSTARS)
            If Not FoundControl Is Nothing Then
                FoundControl.Checked = False
            End If
            Set FoundControl = CommandBars.FindControl(, ID_SVR_SOURCE_SUPPORT)
            If Not FoundControl Is Nothing Then
                FoundControl.Checked = False
            End If
            Control.Checked = True
However the control is never found. I use this same code to find a CheckBox item on the ribbon to activate/deactivate an associated control:
 
        Case ID_CW_STARTDATE_CAPTION
            Control.Checked = Not Control.Checked
            Set FoundControl = CommandBars.FindControl(, ID_CW_STARTDATE)
            If Not FoundControl Is Nothing Then
                FoundControl.Enabled = Not FoundControl.Enabled
            End If
Anyone know what is going on or a better way to control the active Radio selection?
 


-------------
Chris Rowley



Replies:
Posted By: Oleg
Date Posted: 09 October 2007 at 3:09pm
Hi,
Its VERY bad design to use FindControl for such operation
 
Check how we use Update handlers in our sample. Check how we Check only one Visual theme button . Add Variable that indicates last selected Control and Update these Controls in Update handler.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: XpatTech
Date Posted: 08 December 2007 at 8:20pm
Which sample ?


Posted By: Oleg
Date Posted: 09 December 2007 at 4:21am

Hi,

Almost all samples with theme buttons. For example CommandBars\VB\MDISample


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Bernie
Date Posted: 11 December 2007 at 8:16am
Oleg, can you explain why it's a VERY BAD use?


Posted By: ijwelch
Date Posted: 11 December 2007 at 10:58am
Hi Bernie,

I'll butt-in if it's ok:) I don't think Oleg meant it was YOUR bad use. It's just not the way CommandBars works best.

I also used to use FindControl for this kind of thing. It's logical.

Using FindControl is probably a 'fix' they've added for people like you and me, but it is flawed and totally unnecessary once you shift to one of the 2 alternative ways of updating control properties.

I'll explain for anyone browsing what it took me a while to 'get':

One problem is when the user has customized bars and the control appears in multiple places. Using FindControl for EVERY CommandBar  for each Control you want to update, is a pain. The 'Actions' object was added, I believe, to address this.

So, the two options for updating CommabdBarControl properties are:

1. CommandBars.EnableActions and add an Action object for each control you want to update. This way you can call CommandBars.Actions(CONTROL_ID).Checked=False at any time and all instances of the specified control id will be updated.

2. Use the CommandBars_Update event.
There's a bit of a logic shift involved (at least for me) with the Update event. You need to let the condition property dictate the state of the control, not the other way around. eg.

in Update Event (which fires multiple times a second)
Control.Checked=(TextBox1.Text="OK")

in Execute Event
If TextBox1.Text="OK" then
    TextBox1.Text="Not OK"
Else
    TextBox1.Text="OK
End If



Actions are useful when updating a controls' property could take time. The Update event occurs regularly so use Actions when the property is not guaranteed to be instantly accessible. Then (for example when the user chooses to 'Refresh') you can set the Actions(CONTROL_ID).WhateverProperty=Value



Posted By: ijwelch
Date Posted: 11 December 2007 at 11:20am
If only the help file contained info like that this forum would be dead 


Posted By: XpatTech
Date Posted: 11 December 2007 at 11:41am
Absolutely cracking info member_profile.asp?PF=2113&FID=24 - ijwelch , someone just turned the light on in that tunnel up ahead . 


Posted By: Oleg
Date Posted: 11 December 2007 at 3:58pm
Thanks, good description.
 
Bernie - I don't like FindControl because if you have Customization enabled, your user can just remove this control and your code will fail.
its ok if you you don't allow change your menus.
but Actions and update handler  is universal solution - you don't have to think how much controls with this ID you have.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Bernie
Date Posted: 11 December 2007 at 8:11pm
What you guys mentioned is really difficult for me to understand but I think the posts will shed light on some questions to the use of CommandBar.
 
I have never attened any programming training course. I learn on my own. Actually, I am not a programmer but an IELTS teacher and a planning manager for a language center. <Oleg, does this surprise you?> (sorry for my mistakes in English in any posts!) I don't understand "FORMAL METHODS" of programming. However, with efforts, several programs for several business uses have been published by me.
 
It's sometimes not easy to find the way of the Codejoke controls but I personally think the controls are the greatest solution on earth.


-------------
Bernie Ho, Planning Manager + IELTS specialist + part-time programmer
Taiwan, R.O.C



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