#include "fivewin.ch"
#include "ribbon.ch"
#define BTN_WIDTH 12
#define BTN_HEIGHT 12
function test()
Local oDlg
Local xCol, xRow
local t, k, nTotRow, nTotCol
local aSay
local aBtn, nPos
local nMaxVal := 1
nTotCol = 20
nTotRow = 10
aBtn = Array( nTotRow * nTotCol )
aSay = Array( nTotRow )
DEFINE DIALOG oDlg size 850, 600 pixel
xRow:=1
xCol:=10
For t=1 to nTotRow
@ xRow, 1 say alltrim(str(t),2)+"." SIZE BTN_WIDTH,BTN_HEIGHT pixel
For k=1 to nTotCol
nPos = nTotCol * ( t - 1 ) + k
@ xRow, xCol rbbtn aBtn[ nPos ] PROMPT alltrim(str(k, 2)) ;
SIZE BTN_WIDTH,BTN_HEIGHT CENTER ROUND BORDER
xCol += BTN_WIDTH + 5
aBtn[ nPos ]:bAction = BtnAction( k, t, nTotCol, nTotRow, aBtn, aSay, nMaxVal )
next k
@ xRow + 5, xCol say aSay[ t ] PROMPT "Result:" pixel
xRow += BTN_HEIGHT + 5
xCol = 10
next t
ACTIVATE DIALOG oDlg
RETURN NIL
function BtnAction( x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal)
return { | oSelf | CheckStatus( oSelf, x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal ) }
Function CheckStatus( oSelf, x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal )
local nCount := 0
local j
AEval( aBtn, {| oSelf | If( oSelf:lSelected, nCount++, ) }, ( ( y - 1 ) * nTotCol ) + 1, nTotCol )
if nCount <= nMaxVal
aSay[ y ]:Cargo := "Result: "
if oSelf:lSelected
oSelf:lSelected := .F.
else
oSelf:lSelected := .T. .and. nCount < nMaxVal
if ! oSelf:lSelected
MsgStop( "You can't Select" + CRLF + "Max: " + Str( nMaxVal ) )
else
for j = 0 to nTotRow - 1
if aBtn[ j * nTotCol + x ]:lSelected .and. ( j + 1 )#y
MsgStop( "You can't Select this number" + CRLF + "was selected in Row: " + Str( j + 1 ) )
aBtn[ (y - 1) * nTotCol + x ]:lSelected = .F.
aBtn[ (y - 1) * nTotCol + x ]:Refresh()
exit
endif
next
endif
endif
AEval( aBtn, {| oSelf, nIdx | aSay[ y ]:Cargo += If( oSelf:lSelected, Str( nIdx - ( ( y - 1 ) * nTotCol ), 2 ) + " ", "" ) }, ;
( ( y - 1 ) * nTotCol ) + 1, ( ( nTotCol ) ) )
aSay[ y ]:SetText( aSay[ y ]:Cargo )
endif
return nil