This Canvas based Grid gadget is very nicely done.
If someone needs column names to reflect more "traditional" naming convention (A, B, C.....AA, AB, AC... AAA, AAB, AAC... ZZZ) here is my version of the MyGrid_Reset() procedure:
Code: Select all
; needed for MyGrid_Reset()
#ColumnText = 65 ; "A"
#ColumnSpan = 26 ; "A" to "Z"
Procedure.i _MyGrid_Reset(*mg._MyGrid_Type, Rows, Cols)
; Reset everything so Grid can receive/show new data
Protected i, factor.i, bigfactor.i
If rows <= 0 : rows =1 : EndIf
If cols <= 0 : cols =1 : EndIf
*mg\Rows = rows : Dim *mg\RowHeight(rows)
*mg\Cols = cols : Dim *mg\ColWidth(cols) : Dim *mg\ColID(cols)
*mg\LastIndex = (rows+1) * (cols+1) - 1
Dim *mg\gData(*mg\LastIndex)
If ArraySize(*mg\gData()) < 0
Debug "failed to allocate memory for the grid data !... "
ProcedureReturn
EndIf
; initializations
*mg\TopRow = 1
*mg\TopCol = 1
*mg\Row = 1
*mg\Col = 1
;- set column name like a real spread sheet...
For i=#ColumnText To #ColumnText + cols
If i < (#ColumnText + #ColumnSpan)
; A to Z -> total of 26 columns... enough for small stuff.
_MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(i))
ElseIf i < (#ColumnText + #ColumnSpan + (#ColumnSpan * #ColumnSpan))
; AA to ZZ -> 676 columns -> total of 702 columns... nice size.
factor = Int((i - (#ColumnText + #ColumnSpan)) / #ColumnSpan)
Debug factor
_MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(#ColumnText + factor) + Chr(i - #ColumnSpan * (factor + 1)))
ElseIf i < (#ColumnText + #ColumnSpan + (#ColumnSpan * #ColumnSpan) + (#ColumnSpan * #ColumnSpan * #ColumnSpan))
; AAA to ZZZ -> 17576 columns -> total of 18278 columns... that's a lot!
factor = Int((i - (#ColumnText + #ColumnSpan)) / #ColumnSpan)
bigfactor = Int((i - (#ColumnText + (#ColumnSpan * #ColumnSpan) + #ColumnSpan)) / (#ColumnSpan * #ColumnSpan))
Debug Str(factor) + " : " + Str(bigfactor)
_MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), Chr(#ColumnText + bigfactor) + Chr(#ColumnText + factor - (#ColumnSpan * (bigfactor + 1))) + Chr(i - #ColumnSpan * (factor + 1)))
Else
; AAAA to ZZZZ -> 456976 columns -> total of 475254 columns... who needs that?
; out of range; or bigger than 18278 columns
_MyGrid_SetCellText(*mg, 0, i - (#ColumnText -1), "...")
EndIf
Next
For i=1 To rows
_MyGrid_SetCellText(*mg, i, 0, Str(i))
Next
_MyGrid_ChangeColWidth(*mg, #MyGrid_RC_Any, #MyGrid_Default_ColWidth)
_MyGrid_ChangeRowHeight(*mg, #MyGrid_RC_Any, #MyGrid_Default_RowHeight)
*mg\FrozenCol = 0
*mg\FrozenRow = 0
*mg\MoveStatus = #MyGrid_MouseMove_Nothing
*mg\PreviousX = 0
*mg\PreviousY = 0
*mg\NoRedraw = #False
*mg\Color_Line = $CCCCCC
*mg\Color_BlockBack = $FFFFBB
*mg\Color_Background = $808080
*mg\Color_FocusBack = $DBF0E0
*mg\Color_FocusBorder = $009AB6
*mg\WrapText = #True
; adding the 4 default styles : data-cell/frozen-cells/col-header/row-header
ClearList( *mg\LstStyle() )
ClearMap( *mg\DicStyle() )
AddElement(*mg\LstStyle()) ; data area
_MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $FFFFFF, $000000, Font_A8, 0, 1)
AddElement(*mg\LstStyle()) ; frozen-data area
_MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $D7EBFA, $000000, Font_A8, 0, 1)
AddElement(*mg\LstStyle()) ; col-headers
_MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $EB9E85, $FFFFFF, Font_A8, 0, 0)
AddElement(*mg\LstStyle()) ; row-headers
_MyGrid_DefineCurrentStyle(*mg, #MyGrid_Align_Center, $EB9E85, $FFFFFF, Font_A8, 0, 0)
; set min/max/page of scrolls
_MyGrid_AdjustScrolls(*mg)
EndProcedure
For now the code covers 18278 columns...