Page 1 of 1

How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 4:04 am
by hua
Below is the code that I use to test. I couldn't get it to work

Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   local oDlg, oRadMenu
   local nOption := 1

   DEFINE DIALOG oDlg RESOURCE "Radios"

   REDEFINE RADIO oRadMenu VAR nOption ID 110, 120, 130, 140, 150 OF oDlg ;
      WHEN MyFunc()

   REDEFINE BUTTON ID 100 OF oDlg ACTION oRadMenu:aItems[2]:disable()

   REDEFINE BUTTON ID 102 OF oDlg ACTION oRadMenu:aItems[2]:enable()

   ACTIVATE DIALOG oDlg CENTERED

return nil

function MyFunc()
return .t.
 


Code: Select all  Expand view

radios DIALOG 46, 44, 127, 86
STYLE DS_MODALFRAME | 0x4L | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Testing Radio Buttons"
FONT 10, "MS Sans Serif"
{
 GROUPBOX "&Some Radios", 107, 5, 6, 70, 75, BS_GROUPBOX | WS_CHILD | WS_VISIBLE
 CONTROL "&One", 110, "BUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 10, 16, 28, 12
 CONTROL "&Two", 120, "BUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 10, 28, 28, 12
 CONTROL "T&hree", 130, "BUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 10, 40, 28, 12
 CONTROL "&Four", 140, "BUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 10, 52, 28, 12
 CONTROL "F&ive", 150, "BUTTON", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 10, 63, 28, 12
 PUSHBUTTON "&Disable 2", 100, 81, 10, 41, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 PUSHBUTTON "&Enable 2", 102, 81, 24, 41, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 PUSHBUTTON "&Cancel", 2, 81, 38, 41, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP
}
 


TIA

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 5:29 am
by joseluisysturiz
Intenta validar en el ON CHANGE el valor capturado en la VAR del radio, si es dicho valor...has que sea otro y asi lo saltas, basado en la condicion que quieras, es una idea, saludos... :shock:

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 7:00 am
by ukoenig
a working sample .

REDEFINE RADIO oRadio1 VAR nRadio1 ID 170 , 171, 172 OF oFld:aDialogs[ 2 ] UPDATE
AEval( oRadio1:aItems, { | oRad | oRad:lTransparent := .T., ;

oRadio1:aItems[2]:Disable(), ;
oRad:SetFont ( oFontText ), ;
oRad:nClrText := 255 } )


Image

Best regards
Uwe :)

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 9:08 am
by Enrico Maria Giordano
Hua,

please comment out WHEN MyFunc() and it will work fine.

EMG

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 9:13 am
by hua
Gracias Jose. Already tried but didn't work.


Uwe, my self-contained sample has a WHEN clause. I suspect that is what is interfering with manual disable/enable of the item

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 9:16 am
by hua
Thanks for confirming Enrico. I did suspect that WHEN was the cause.

I may have to come with a workaround that will set bWhen to nil when I want to disable just that one item.

Re: How to disable an item of a radio control

PostPosted: Tue Jun 09, 2015 2:46 pm
by ukoenig
Your modified sample, using a function on button-action

Image

Code: Select all  Expand view

#include "FiveWin.ch"

FUNCTION MAIN()
local oDlg, oRadMenu
local nOption := 1, oFont, lStatus := .T.

oFont := TFont():New("Arial",0,-14,.F.,.T.,0,0,0,.F. )

DEFINE DIALOG oDlg RESOURCE "Radios"

REDEFINE RADIO oRadMenu VAR nOption ID 110, 120, 130, 140, 150 OF oDlg  
AEval( oRadMenu:aItems, { | oRad | oRad:lTransparent := .T., ;
     oRad:SetFont ( oFont ), ;
     oRad:nClrText := 255 } )

REDEFINE BUTTON ID 100 OF oDlg ;
ACTION ( lStatus := MYFUNC(1), AEval( oRadMenu:aItems, { | oRad | ;
     IIF( lStatus = .T., oRadMenu:aItems[2]:Enable(), ;
               oRadMenu:aItems[2]:Disable() ) } ) )

REDEFINE BUTTON ID 102 OF oDlg ;
ACTION ( lStatus := MYFUNC(2), AEval( oRadMenu:aItems, { | oRad | ;
IIF( lStatus = .T., oRadMenu:aItems[2]:Enable(), ;
              oRadMenu:aItems[2]:Disable() ) } ) )

ACTIVATE DIALOG oDlg CENTERED

oFont:End()

RETURN NIL

// ---------

FUNCTION MYFUNC(nStat)
lValue := .F.

IF nStat = 2
     lValue := .T.
ENDIF

RETURN lValue
 


best regards
Uwe :)

Re: How to disable an item of a radio control

PostPosted: Wed Jun 10, 2015 1:45 am
by hua
Thanks Uwe!