Really nice trick Pablo.
At this juncture I wish to share another trick (which Claudio taught me) to align differently in a column. I am using this trick for a grid to show like a property sheet.
Code: Select all
#include "hmg.ch"
Function Main
PRIVATE aRows [20][3]
aRows [1] := { 113.12, date(), '1', 1, .t. }
aRows [2] := { 123.12, date(), '2', 2, .f. }
aRows [3] := { 133.12, date(), '3', 3, .t. }
aRows [4] := { 143.12, date(), "A", 4, .f. }
aRows [5] := { 153.12, date(), '2', 5, .t. }
aRows [6] := { 163.12, date(), '3', 6, .f. }
aRows [7] := { 173.12, date(), "B", 7, .t. }
aRows [8] := { 183.12, date(), '2', 8, .f. }
aRows [9] := { 193.12, date(), "A", 9, .t. }
aRows [10] := { 113.12, date(), '1', 10, .f. }
aRows [11] := { 123.12, date(), '2', 11, .t. }
aRows [12] := { 133.12, date(), "C", 12, .f. }
aRows [13] := { 143.12, date(), '1', 13, .t. }
aRows [14] := { 153.12, date(), '2', 14, .f. }
aRows [15] := { 163.12, date(), '3', 15, .t. }
aRows [16] := { 173.12, date(), '1', 16, .f. }
aRows [17] := { 183.12, date(), "B", 17, .t. }
aRows [18] := { 193.12, date(), '3', 18, .f. }
aRows [19] := { 113.12, date(), '1', 19, .t. }
aRows [20] := { 123.12, date(), '2', 20, .f. }
for i := 1 to 20
if ascan( {'A','B','C'} , aRows[ i, 3 ] ) == 0
aRows[ i, 3 ] := rightalignedtext( aRows[ i, 3 ], 120, 'Arial', 9, .f. )
endif
next i
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 600 ;
HEIGHT 430 ;
TITLE 'Mixed Data Type Grid Test' ;
MAIN NOSIZE NOMAXIMIZE
DEFINE STATUSBAR FONT "Courier New" SIZE 9
STATUSITEM PadC("Try by clicking at 3rd column and see the ComboBox items",84)
END STATUSBAR
@ 10,10 GRID Grid_1 ;
WIDTH 576 ;
HEIGHT 330 ;
HEADERS {'Column 1','Column 2','Column 3','Column 4','Column 5'} ;
WIDTHS {120,120,120,120,70} ;
ITEMS aRows ;
EDIT ;
JUSTIFY { GRID_JTFY_RIGHT,GRID_JTFY_CENTER,GRID_JTFY_LEFT,GRID_JTFY_RIGHT, GRID_JTFY_LEFT } ;
COLUMNCONTROLS { {'TEXTBOX','NUMERIC','$ 999,999.99'} , {'DATEPICKER','DROPDOWN'} , {'TEXTBOX'}, { 'SPINNER' , 1 , 20 } , { 'CHECKBOX' , 'Yes' , 'No' } } ;
COLUMNVALID {{ || .T.},{ || .T.},{ || Valid3()},{ || .T.},{ || .T.}} ;
CELLNAVIGATION
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil
Function Valid3()
LOCAL lRet:=.F.
LOCAL c:=This.CellColFocused
LOCAL r:=This.CellRowFocused
LOCAL xValue:=This.CellValue
If !Empty(This.CellValue)
lRet:=.T.
If ascan( {'A','B','C'}, xValue ) == 0
This.CellValue := rightalignedtext( xValue, 120, 'Arial', 9, .f. )
endif
Endif
Return lRet
function rightalignedtext( cData, nWidth, cFont, nSize, lBold )
local hDC, BTstruct
local nTextSize := 0
local aTextData := {}
local nType := BT_TEXT_OPAQUE
nWidth := nWidth - 15
hDC := BT_CreateDC ( , BT_HDC_DESKTOP, @BTstruct)
if lBold
nType := BT_TEXT_BOLD
endif
do while nTextSize < nWidth
aTextData := BT_DrawTextSize ( hDC, cData, cFont, nSize, nType )
nTextSize := aTextData[ 1 ]
if nTextSize < nWidth
cData := ' ' + cData
endif
enddo
BT_DeleteDC (BTstruct)
return cData