Setting up a table with varying numbers of rows

Just starting out? Need help? Post your questions and find answers here.
RNBW
User
User
Posts: 71
Joined: Thu Jan 02, 2014 5:01 pm

Re: Setting up a table with varying numbers of rows

Post by RNBW »

Just to carry on with my little grid exercise.

I have used a quick and dirty method via the console to input the number of rows in the grid. I have added 1 to this total so that the rows of actual data displayed is correct.

The columns are of varying widths and these are displayed.

I have added loops to put into the header row to show column numbers and also to display row numbers.

Code: Select all

;produces a grid of textboxes
If OpenConsole()
TotalRows.i = 8

Print ("How many rows of Data? ")
sTotalRows.s = Input()
TotalRows = Val(sTotalRows) +1
EndIf


; Open window
#WindowWidth  = 900
#WindowHeight = 550

If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Grid Demonstration", #PB_Window_MinimizeGadget)

;input "Number of Rows in Table: "; TotalRows
;TotalRows = 8
VisibleRows = 6

vpos = 50 : rowHigh = 20 

lDist.i = 30

For row = 1 To TotalRows
  For col = 1 To 8
    
    Select col
      ;First column 
      Case 1
        xpos = lDist : width = 65
      ;Second Column 
      Case 2 
        xpos = lDist+65 : width = 380
      ;Columns 3 To 8
      Case 3,4,5,6,7,8 
        xpos = lDist+col*65+(445-65*3) : width = 65
    EndSelect
            
    gNum.i = row*8-8+col
    ; NOTE: add 1 to both width and rowHigh and this removes the duplication 
    ; of the border of boxes, resulting in a thinner line.
    StringGadget(gNum, xpos, vpos+row*rowHigh-rowHigh, width+1, rowHigh+1, "")
    Debug gNum
  Next col   
Next row 

For col = 2 To 8
  String.s = "Col " + Str(col-1)
  gNum = 1*8-8 + col
  SetGadgetText(gNum,String)
Next

; This loop doesn't work.  Possibly do Select..Case
For row = 2 To TotalRows
  For col =1 To 1
    String = "Row " + Str(row-1)
    gNum = row*8-8 + col
    SetGadgetText(gNum,String)
  Next
Next

 Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Debug "Event fired on Gadget : " + Str(EventGadget())
    EndSelect
  Until Event = #PB_Event_CloseWindow Or Quit = #True
 
EndIf
I now need to do the following:
1. Make the row header and the row references Read-Only.
2. Colour the header row and the left hand column.
3. Enter data into the other data cells.

I'm a bit busy now, so progress is slow, but I hope that anyone interested in this little exercise will bear with me.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Setting up a table with varying numbers of rows

Post by TI-994A »

RNBW wrote:I now need to do the following:
1. Make the row header and the row references Read-Only.
2. Colour the header row and the left hand column.
This should do it:

Code: Select all

    If row = 1 Or col = 1
      style = #PB_String_ReadOnly
    Else
      style = 0
    EndIf
    
    StringGadget(gNum, xpos, vpos+row*rowHigh-rowHigh, width+1, rowHigh+1, "", style)
    
    If row = 1  Or col = 1
      SetGadgetColor(gNum, #PB_Gadget_FrontColor, RGB(200, 255, 255))
      SetGadgetColor(gNum, #PB_Gadget_BackColor, RGB(0, 0, 100))
    EndIf
Just one approach, in line with your coding structure. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
RNBW
User
User
Posts: 71
Joined: Thu Jan 02, 2014 5:01 pm

Re: Setting up a table with varying numbers of rows

Post by RNBW »

Hi TI-994A

Thank you for the code. That is just what I am looking for. I particularly like the dark blue background colour. I usually use Cyan in these circumstances, but the dark blue is very distinctive.

Ray
Post Reply