Author |
Topic: Data Grid with Specified Column Widths (Read 3353 times) |
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #15 on: Oct 26th, 2015, 4:25pm » |
|
Perhaps you had a little Freudian slip? 
on Oct 26th, 2015, 4:19pm, RNBW wrote:| Sorry about the typo. It should be handle not hassle. |
|
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Data Grid with Specified Column Widths
« Reply #16 on: Oct 26th, 2015, 5:17pm » |
|
on Oct 26th, 2015, 4:17pm, RNBW wrote:| I presume I am using the common controls prevalent for Windows 10 |
|
I'm not sure whether Windows 10 comes with only Common Controls v6 (or later) or whether an earlier version is supplied as well for compatibility. To find out you would have to modify the LBB manifest (or, more safely, the manifest in a compiled EXE) using a resource editor.
There is some relevant information here:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh298349.aspx
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #17 on: Oct 27th, 2015, 01:03am » |
|
I've been fighting this for a while now and have given up for the night.
I'm trying to put column headings over the grid. Started out with textboxes, but I can't get the "print" to work to the textbox.
I added the following code right before the part where the grid is drawn. It prints the boxes in a fine manner, but I can't get the text to print.
I must not understand something. Any enlightenment?
Code:
cumColumnWidth = 0
for col = 1 to numberOfColumns
'stylebits #w.collbl, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
textbox #w.collbl, leftMargin+cumColumnWidth, cellMargin+0, columnWidth(col)+1, rowHeight+1
maphandle #w.collbl, "#w.collbl";col
h$ = "#w.collbl";col
' print #handle.ext, "a string"
print #h$, columnLabel$(col);
'print #w.collbl1 "TEST"
cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
next
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Data Grid with Specified Column Widths
« Reply #18 on: Oct 27th, 2015, 09:33am » |
|
on Oct 27th, 2015, 01:03am, pnlawrence wrote:| I'm trying to put column headings over the grid. Started out with textboxes, but I can't get the "print" to work to the textbox. |
|
The code you listed appears to be trying to print to a textbox before the textbox even exists (i.e. before the open statement)! You will need two loops, one to define the textboxes before the open, and the other to print to the textboxes after the open.
If you do use textboxes for the column headers remember to make them read-only: you don't want the user to be able to edit them! You will also want to remove the tabstop style from the header boxes, because it isn't helpful to allow the user to tab through them:
Code: stylebits #w.collbl, _ES_READONLY, _WS_BORDER or _WS_TABSTOP, 0, 0
Possibly centering the heading text in the boxes would be desirable too:
Code: stylebits #w.collbl, _ES_READONLY or _ES_CENTER, _WS_BORDER or _WS_TABSTOP, 0, 0
You could alternatively use statictext controls for the headers (perhaps with an added border) instead of textboxes, which would avoid some of these complications.
Richard.
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Data Grid with Specified Column Widths
« Reply #19 on: Oct 27th, 2015, 09:51am » |
|
Richard I downloaded a resource editor and found that LB 4.04 and 4.5 both indicated Common Control 6.0.0 in their Manifests as did your own BB4W.
As far as I can see from MS info, the latest version is 6.1, but the table I got this from shows this for Windows 7. No mention is made of layer Windows versions.
Ray
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #20 on: Oct 27th, 2015, 10:29am » |
|
Had to be something to do with ignorance. Now I know something new. Only 5492 lessons left to go!
Guess I'll have to use statictext because putting the grid in a sub is my goal. The window won't normally be open at that point. We'll see, though.
Quote:You could alternatively use statictext controls for the headers (perhaps with an added border) instead of textboxes, which would avoid some of these complications. |
|
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Data Grid with Specified Column Widths
« Reply #21 on: Oct 27th, 2015, 10:54am » |
|
on Oct 27th, 2015, 10:29am, pnlawrence wrote:Guess I'll have to use statictext because putting the grid in a sub is my goal. The window won't normally be open at that point. We'll see, though. |
|
It would be part of the set up of the table and the printing of the text in the headings would be after you had opened the window for the rest of the table. so if the problem about it being in a sub applies to the headings it will also apply to the rest of the table.
Richard's advice is good and you just need to set up a loop to construct textboxes for the headings. After opening the window just print the text into the textbox headings.
Richard provided an example of how to do this in the scrolling example at "Re: Variable Number Of Rows Of Texboxes « Reply #6 on: 04/03/15 at 10:46am »" in the Liberty Basic Language section.
Ray
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: Data Grid with Specified Column Widths
« Reply #22 on: Oct 27th, 2015, 11:52am » |
|
pnlawrence, "grid in a sub": - will it be created via sub, and then control passed to main program - or will it be kind of "modal window" - you call a sub, it shows grid, you vew/change stuff/then close window - (only) then you return from sub? Just curious.
|
| « Last Edit: Oct 27th, 2015, 11:53am by tsh73 » |
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #23 on: Oct 27th, 2015, 1:17pm » |
|
At this point, the "modal" part is the only reason I'm developing the sub.
However, I do intend to leave out the "modal" part at some point, but for another project.
I can see this working out both ways, but not necessarily together in the same program.
That's why I'm having a few problems with the old adage, "Which came first, the sub or the window?" 
Quote:- will it be created via sub, and then control passed to main program - or will it be kind of "modal window" - you call a sub, it shows grid, you vew/change stuff/then close window - (only) then you return from sub? |
|
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Data Grid with Specified Column Widths
« Reply #24 on: Oct 27th, 2015, 3:26pm » |
|
on Oct 27th, 2015, 1:17pm, pnlawrence wrote:| That's why I'm having a few problems with the old adage, "Which came first, the sub or the window?" |
|
I wouldn't expect you to have much trouble incorporating your code in a SUB, but bear in mind that in LB/LBB handles are automatically global but handle variables have the same scoping rules as any other variables. Since it is likely that your code will use both, this could be a source of confusion.
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #25 on: Oct 28th, 2015, 12:06am » |
|
I was anticipating that the results of input to the "modal" grid would be returned (from the sub) in an array set up for that purpose. In that case the grid window would be an entry/edit window and everything should be contained within and the scope of variables should be local to the sub.
In the case where the code is not "modal" in operation, but is the main user input screen, I would anticipate the "cells" of the grid would be read with locally scoped variables.
Do I understand that correctly? It is all new to me.
I am not sure of the handles that are produced by MAPHANDLE or the handles that those handles are "mapped" from --- the original handles. Does the original handle just go away after using MAPHANDLE?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Data Grid with Specified Column Widths
« Reply #26 on: Oct 28th, 2015, 12:54pm » |
|
on Oct 28th, 2015, 12:06am, pnlawrence wrote:| I was anticipating that the results of input to the "modal" grid would be returned (from the sub) in an array set up for that purpose. |
|
In LB all arrays are global; it's a significant limitation but may actually make things easier for you.
Quote:| Does the original handle just go away after using MAPHANDLE? |
|
Yes, effectively it ceases to exist after using MAPHANDLE.
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #27 on: Oct 31st, 2015, 11:57am » |
|
Here is what I am working on/with for now. I probably won't do much more generically for posting, but will probably start running with my own version of my own version! :o
The demo code is in the next post. Just put them together. It is kind of clunky (ok, really clunky), but I'm sure y'all can keep up! ;)
EDIT: Corrected single digit handle index for the grid "boxes" with a two digit zero padded left handle index.
Code:
sub gridSetup topMargin, numberOfRows, numberOfColumns, leftMargin, cellMargin, rowHeight, labelFormat
' Place a grid window of text and combo boxes for user input
' Uses window handle: #gridWnd
' Tremendous thanks to Richard Russell and Ray(RNBW) on the LBB forum for contributing the most.
' Last Update: 11/02/2015 6:33:00 PM - pnlawrence
'
' =================================================================================================
' Parameters required:
' topMargin - indent below column headers/labels
' numberOfRows
' numberOfColumns
' leftMargin - an indent for the grid left side
' cellMargin - space around the cells of the grid (not left side)
' rowHeight - boxes use this. Depends on windows font size.
' labelFormat - bit-based format byte:
' BIT VAL FORMAT CHARACTERISTIC (lower number bits take precedence on conflict
' 0 1 no column label; no top margin (default is UPPERCASE, no border)
' 1 2 no column label; create top margin
' 2 4 column label in LOWERCASE
' 3 8 column label in PROPERCASE (not implemented)
' 4 16 column label with border
' 5
' 6
' 7
'
' Arrays necessary with data loaded (1-based):
' columnWidth(numberOfColumns) ' contains width data for each column
' columnType(numberOfColumns) ' type of box for each column: 0=textbox, 1=combobox1, 2=combobox2
' columnLabel$(numberOfColumns) ' contains label text for column header/label (see labelFormat for text case)
' comboArray1$(10) ' contains data for combo box 1 (needs REDIM for number of items stored)
' comboArray2$(10) ' contains data for combo box 2 (needs REDIM for number of items stored)
' =================================================================================================
' set the label format variables
NOLABEL = (labelFormat AND 1) OR (labelFormat AND 2)
NOTOPMARGIN = labelFormat AND 1
LOWCASELABEL = labelFormat AND 4
PROPERCASELABEL = labelFormat AND 8 ' not implemented as of 10/28/2015
LABELBORDER = labelFormat AND 16 ' add a border
' create the column labels per the labelFormat
if NOLABEL = 0 then ' create label
cumColumnWidth = 0
for col = 1 to numberOfColumns
if LOWCASELABEL then ' label lower case
statictext #gridWnd.collbl, lower$(columnLabel$(col)),leftMargin+cumColumnWidth, cellMargin, columnWidth(col)+1, rowHeight-2
else ' label uppper case
statictext #gridWnd.collbl, upper$(columnLabel$(col)),leftMargin+cumColumnWidth, cellMargin, columnWidth(col)+1, rowHeight-2
end if
if LABELBORDER then ' create border
stylebits #gridWnd.collbl,_SS_CENTER or _WS_BORDER,0,0,0
else ' no border
stylebits #gridWnd.collbl,_SS_CENTER,_WS_BORDER,0,0
end if
cumColumnWidth = cumColumnWidth + columnWidth(col) + 1 + cellMargin
next
end if
' start with first row/column
cumColumnWidth = 0
if NOTOPMARGIN then
cumRowHeight = 0
else
cumRowHeight = topMargin ' leaves room for column headers
end if
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
stylebits #gridWnd.cell, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
textbox #gridWnd.cell, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight+1
rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
case 1
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #gridWnd.cell, comboArray1$(), [selectionGridCombo1], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
case 2
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #gridWnd.cell, comboArray2$(), [selectionGridCombo2], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
rc$=right$("00"+str$(row),2)+right$("00"+str$(col),2)
maphandle #gridWnd.cell, "#gridWnd.cell"+rc$ ';row;col
end select
cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col) + 1
next col
cumColumnWidth = 0
cumRowHeight = cellMargin + cumRowHeight + rowHeight + 1
next row
end sub
|
| « Last Edit: Nov 2nd, 2015, 11:35pm by joker » |
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #28 on: Oct 31st, 2015, 11:59am » |
|
Demo code for the Data Grid subroutine in the previous post. Code:
'Last Update: 10/31/2015 6:29:34 AM
' Demo is clunky, but provides a platform. pnlawrence
'Last Update: 10/30/2015 5:31:45 AM
' Completed demo of grid subroutine with formatted columns. pnlawrence
'Last Update: 10/30/2015 3:48:16 AM
' Column label positions & widths. pnlawrence
'Last Update: 10/29/2015 8:43:09 PM
' Added window size relative to numRows & numCols & column labels. pnlawrence
'Last Update: 10/28/2015 8:37:41 PM
' Added labelFormat. pnlawrence
'Last Update: 10/28/2015 5:31:47 AM
' Adding the labelFormat byte to use instead of other ways. pnlawrence
'Last Update: 10/27/2015 6:38:34 AM
' Fixed column header code. pnlawrence
'Last Update: 10/26/2015 8:04:22 PM
' Working on column heading labels. pnlawrence
'Last Update: 10/26/2015 5:22:52 PM
' Adding a column label row in gridSetup. pnlawrence
'Last Update: 10/26/2015 11:46:38 AM
' Added window controls. pnlawrence
'Last Update: 10/26/2015 11:21:25 AM
' Added grid drawing subroutine. pnlawrence
' Place a grid window of text and combo boxes for user input. The grid is "modal".
' Tremendous thanks to Richard Russell and Ray(RNBW) on the LBB forum for contributing the most.
'
' Begin with the main window
Nomainwin
gosub [MAINWINSETUP]
gosub [GRIDVARIABLESSETUP]
gosub [GRIDWINDOWSETUP]
gosub [GRIDCONTROLSETUP]
gosub [GRIDSETUP]
'===================================
[MAINLOOP]
wait
'===================================
[selectionGridCombo1]
' dummy
wait
[selectionGridCombo2]
' dummy
wait
[PRINTGRID]
[SAVEGRID]
[EDITPERSON]
[QUITGRID]
close #gridWnd
wait
[PERSON]
[QUIT]
close #gridWnd
close #mainWnd
END
[GRIDWINDOWSETUP]
' Determine the width of the window
WindowWidth = leftMargin ' passing value for cumulative column width
for col = 1 to numberOfColumns
WindowWidth = WindowWidth + columnWidth(col) + 1 + cellMargin
next
WindowWidth = WindowWidth + cellMargin*5 + cellMargin ' add right margin
' Determine the height of the window
if (labelFormat AND 1) OR (labelFormat AND 2) then ' no label row
WindowHeight = 60 ' start with room for caption and menu bar
else
WindowHeight = topMargin + 60 ' start with room for caption & menu bar & top margin
end if
for row = 1 to numberOfRows
WindowHeight = cellMargin + WindowHeight + rowHeight + 1
next
WindowHeight = WindowHeight + cellMargin
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
LowerRightX=UpperLeftX+WindowWidth
LowerRightY=UpperLeftY+WindowHeight
'print "WindowWidth (";WindowWidth;")"
'print "WindowHeight (";WindowHeight;")"
'print "Upper(";UpperLeftX;",";UpperLeftY;")"
'print "Lower(";LowerRightX;",";LowerRightY;")"
'print "Button (";LowerRightX-200;",";LowerRightY-200;")
return
[GRIDCONTROLSETUP]
Menu #gridWnd, "File", "Save GRID", [SAVEGRID], "Quit", [QUITGRID]
Menu #gridWnd, "Person", "Edit / Add", [EDITPERSON]
Menu #gridWnd, "Report", "Print GRID", [PRINTGRID]
return
[GRIDSETUP] ' create the grid
call gridSetup topMargin, numberOfRows, numberOfColumns, leftMargin, cellMargin, rowHeight, labelFormat
Stylebits #gridWnd, 0,_WS_MAXIMIZEBOX,0,0
open "DATA INPUT GRID" for window as #gridWnd
#gridWnd "trapclose [QUITGRID]"
#gridWnd "font ms_sans_serif 10"
' set up the column headings if necessary
return
[OUTPUT]
#mainWnd.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
h$ = "#gridWnd.cell";row;col
#h$ "!contents? b$"
case 1
h$ = "#gridWnd.cell";row;col
#h$ "contents? b$"
case 2
h$ = "#gridWnd.cell";row;col
#h$ "contents? b$"
end select
' printing and/or saving the cell is done here
print #mainWnd.ted, row;":";col;" ";b$
next
next
wait
[GRIDVARIABLESSETUP]
' =================================================================================================
' Parameters required:
' topMargin - indent below column headers
' numberOfRows
' numberOfColumns
' leftMargin - an indent for the grid
' cellMargin - space around the cells of the grid
' rowHeight - text boxes use this. Depends on font size.
' labelFormat - bit-based format byte:
' BIT VAL FORMAT CHARACTERISTIC (lower number bits take precedence on conflict
' 0 1 no column label; no top margin
' 1 2 no column label; create top margin
' 2 4 column label in LOWERCASE (default is UPPERCASE)
' 3 8 column label in PROPERCASE (default is UPPERCASE)
' 4 16 column label with border (default is no border)
' 5
' 6
' 7
'
' Arrays with data loaded to be made available (1-based):
' columnWidth(numberOfColumns) ' contains width for each column
' columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
' columnLabel$(numberOfColumns) ' contains labels for column header
' comboArray1$(10) ' contains data for combo box 1 (needs REDIM for number of items stored)
' comboArray2$(10) ' contains data for combo box 2 (needs REDIM for number of items stored)
' dataArray$(10) ' contains data returned from the grid cells. Will be REDIM to fit the grid.
' =================================================================================================
labelFormat = 0
topMargin = 25
numberOfRows = 20
numberOfColumns = 10
leftMargin = 5
cellMargin = 3
rowHeight = 25
dim columnWidth(10) ' contains width for each column
dim columnType(10) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim columnLabel$(10) ' contains the text labels above the columns
dim comboArray1$(10) ' contains data for combo box (needs REDIM for number of items stored)
dim comboArray2$(10) ' contains data for combo box (needs REDIM for number of items stored)
columnWidth(1) = 100 : columnType(1) = 1 : columnLabel$(1) = "One"
columnWidth(2) = 100 : columnType(2) = 1 : columnLabel$(2) = "Two"
columnWidth(3) = 50 : columnType(3) = 0 : columnLabel$(3) = "Three"
columnWidth(4) = 50 : columnType(4) = 0 : columnLabel$(4) = "Four"
columnWidth(5) = 30 : columnType(5) = 0 : columnLabel$(5) = "Five"
columnWidth(6) = 50 : columnType(5) = 0 : columnLabel$(6) = "Six"
columnWidth(7) = 50 : columnType(5) = 0 : columnLabel$(7) = "Seven"
columnWidth(8) = 20 : columnType(5) = 0 : columnLabel$(8) = "8"
columnWidth(9) = 50 : columnType(5) = 0 : columnLabel$(9) = "Nine"
columnWidth(10) = 50 : columnType(5) = 0 : columnLabel$(10) = "Ten"
' 550
comboArray1$(1) = "1"
comboArray1$(2) = "22"
comboArray1$(3) = "333"
comboArray1$(4) = "FOUR"
comboArray1$(5) = "FIVEX"
comboArray1$(6) = "666666"
comboArray1$(7) = "7777777"
comboArray1$(8) = "88888888"
comboArray1$(9) = "999999999"
comboArray1$(10) = "12345678901234567890123456789012345678901234567890"
comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"
return
[MAINWINSETUP]
WindowWidth = DisplayWidth - 200
WindowHeight = DisplayHeight - 100
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
Stylebits #mainWnd, 0,_WS_MAXIMIZEBOX,0,0
texteditor #mainWnd.ted, UpperLeftX+50, UpperLeftY+50, 200, 300
button #mainWnd.btn, " OUTPUT ", [OUTPUT], LR, 170,10
button #mainWnd.btn, " PERSON ", [PERSON], LR, 70, 10
open "MAIN WINDOW" for window as #mainWnd
#mainWnd "trapclose [QUIT]"
#mainWnd "font ms_sans_serif 10"
return
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Data Grid with Specified Column Widths
« Reply #29 on: Nov 1st, 2015, 10:15am » |
|
Ran across this comment in the LB help file:
Quote:NOTE: Branch labels inside functions and subroutines are not visible to code outside those functions and subroutines. If code in the main program tries to access a branch label inside a function or subroutine, this will cause an error. Likewise, functions and subroutines cannot use branch labels defined outside their scope. |
|
The above sub references branch routines outside the sub in the combobox "validation" branches. I don't get any kind of compiler message or error message during execution about this.
Actually, it works just fine from the combobox branch labels.
So, that comment in the LB help file must only refer to program branches within subs.
|
|
Logged
|
|
|
|
|