Trouble with xtpControlRadioButton |
Post Reply |
Author | |
clubside
Newbie Joined: 08 October 2007 Location: United States Status: Offline Points: 1 |
Post Options
Thanks(0)
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
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
XpatTech
Groupie Joined: 26 November 2007 Location: United Kingdom Status: Offline Points: 37 |
Post Options
Thanks(0)
|
Which sample ?
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi, Almost all samples with theme buttons. For example CommandBars\VB\MDISample
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Bernie
Senior Member Joined: 05 July 2007 Location: Taiwan Status: Offline Points: 109 |
Post Options
Thanks(0)
|
Oleg, can you explain why it's a VERY BAD use?
|
|
ijwelch
Senior Member Joined: 20 June 2006 Status: Offline Points: 262 |
Post Options
Thanks(0)
|
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 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 |
|
ijwelch
Senior Member Joined: 20 June 2006 Status: Offline Points: 262 |
Post Options
Thanks(0)
|
If only the help file contained info like that this forum would be dead
|
|
XpatTech
Groupie Joined: 26 November 2007 Location: United Kingdom Status: Offline Points: 37 |
Post Options
Thanks(0)
|
Absolutely cracking info ijwelch , someone just turned the light on in that tunnel up ahead .
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
Bernie
Senior Member Joined: 05 July 2007 Location: Taiwan Status: Offline Points: 109 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |