Here's a simple text grid to illustrate the implementation of your requirements. It uses string gadgets, so the cells are editable, laid out evenly to fit the given size. This could easily be modified to accommodate varying cell-widths, and even replaced with text-gadgets for read-only cells. The grid is encapsulated within a container gadget, allowing it to be moved easily. Two convenience functions have been included to set the cell values and row-visibility.
Code: Select all
Enumeration
#MainWindow
#ToggleView
#MoveGrid
EndEnumeration
Dim myTextGrid(7, 6)
Procedure TextGrid(x, y, width, height, Array gridInfo(2))
Protected cellSpacing = 5
Protected rows = ArraySize(gridInfo(), 1)
Protected columns = ArraySize(gridInfo(), 2)
Protected cellX = cellSpacing, cellY = cellSpacing
Protected cellHeight = (height - (cellSpacing * (rows + 2))) / (rows + 1)
Protected cellWidth = (width - (cellSpacing * (columns + 2))) / (columns + 1)
gridID = ContainerGadget(#PB_Any, x , y, width, height, #PB_Container_Flat)
For row = 0 To rows
For column = 0 To columns
gridInfo(row, column) = StringGadget(#PB_Any, cellX, cellY, cellWidth, cellHeight,
"Cell " + Str(row) + ", " + Str(column),
#PB_Text_Center | #PB_String_BorderLess)
SetGadgetColor(gridInfo(row, column), #PB_Gadget_BackColor, #White)
cellX + (cellWidth + cellSpacing)
Next column
cellX = cellSpacing
cellY + (cellHeight + cellSpacing)
Next row
CloseGadgetList()
ProcedureReturn gridID
EndProcedure
Procedure ShowGridRows(row, state = #False)
Shared myTextGrid()
For column = 0 To ArraySize(myTextGrid(), 2)
HideGadget(myTextGrid(row, column), state)
Next column
EndProcedure
Procedure SetGrid(row, column, text.s, frontColour = 0, backColour = 16777215)
Shared myTextGrid()
SetGadgetText(myTextGrid(row, column), text)
SetGadgetColor(myTextGrid(row, column), #PB_Gadget_FrontColor, frontColour)
SetGadgetColor(myTextGrid(row, column), #PB_Gadget_BackColor, backColour)
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 1000, 700, "Simple Text Grid", wFlags)
ButtonGadget(#ToggleView, 10, 650, 980, 40, "CLICK TO TOGGLE-VIEW LAST TWO ROWS")
ButtonGadget(#MoveGrid, 10, 600, 980, 40, "CLICK TO MOVE TEXT GRID")
myGrid = TextGrid(10, 10, 700, 400, myTextGrid())
SetGrid(0, 0, "Click cell to edit...")
SetGrid(0, 1, "Manually set...", RGB(255, 255, 0), RGB(255, 0, 0))
SetGrid(3, 3, "Another one...", RGB(0, 0, 255), RGB(0, 255, 255))
SetGrid(6, 5, "Me too!", RGB(0, 100, 0), RGB(0, 255, 0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #MoveGrid
x = Random(300, 10)
y = Random(200, 10)
ResizeGadget(myGrid, x, y, #PB_Ignore, #PB_Ignore)
Case #ToggleView
If state
state = #False
Else
state = #True
EndIf
ShowGridRows(6, state)
ShowGridRows(7, state)
EndSelect
EndSelect
Until appQuit = 1
Hope you'd find it useful.