Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - Trouble with xtpControlRadioButton
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Trouble with xtpControlRadioButton

 Post Reply Post Reply
Author
Message
clubside View Drop Down
Newbie
Newbie
Avatar

Joined: 08 October 2007
Location: United States
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote clubside Quote  Post ReplyReply Direct Link To This Post Topic: Trouble with xtpControlRadioButton
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
XpatTech View Drop Down
Groupie
Groupie
Avatar

Joined: 26 November 2007
Location: United Kingdom
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote XpatTech Quote  Post ReplyReply Direct Link To This Post Posted: 08 December 2007 at 8:20pm
Which sample ?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Bernie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 July 2007
Location: Taiwan
Status: Offline
Points: 109
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bernie Quote  Post ReplyReply Direct Link To This Post Posted: 11 December 2007 at 8:16am
Oleg, can you explain why it's a VERY BAD use?
Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post Posted: 11 December 2007 at 11:20am
If only the help file contained info like that this forum would be dead 
Back to Top
XpatTech View Drop Down
Groupie
Groupie
Avatar

Joined: 26 November 2007
Location: United Kingdom
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote XpatTech Quote  Post ReplyReply Direct Link To This Post Posted: 11 December 2007 at 11:41am
Absolutely cracking info ijwelch , someone just turned the light on in that tunnel up ahead . 
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Bernie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 July 2007
Location: Taiwan
Status: Offline
Points: 109
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bernie Quote  Post ReplyReply Direct Link To This Post 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
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.219 seconds.