Author |
Topic: Data Grid with Specified Column Widths (Read 3351 times) |
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Data Grid with Specified Column Widths
« Thread started on: Oct 26th, 2015, 02:21am » |
|
After studying the "data grid" project on the two different forums, I've been working on a version that suits my project.
Thanks to both Richard and RNBW for the work they have done. My ultimate goal is a subroutine.
I decide to add both specified column widths and type of column. My limited Windows experience is now showing, because I'm having a problem.
Garnering data from the previous iterations, I have the column width part working fine.
I have gone beyond my experience level in trying to make the grid have both textboxes and comboboxes within the same grid. I seem to be able to build the grid by my specifications, but I don't seem to have something correct in reading the data from the grid.
Code:
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox.
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns.
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code.
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell
numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
rowHeight = 20
dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)
columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 0
columnWidth(5) = 35 : columnType(5) = 0
comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"
cumColumnWidth = 0
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
if columnType(col) = 0 then
textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
maphandle #w.tb, "#w.tb";row;col
else
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
combobox #w.cb, comboArray$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
maphandle #w.cb, "#w.cb";row;col
end if
cumColumnWidth = cumColumnWidth + columnWidth(col)
next col
cumColumnWidth = 0
next row
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid" for window as #w
'#w.tb42 "Some text"
wait
[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
if columnType(col) = 0 then
h$ = "#w.tb";row;col
else
h$ = "#w.cb";row;col
end if
'print #handle.ext, "contents? text$"
#h$ "!contents? b$"
print #w.ted, row;":";col;" ";b$
next
next
wait
[validCombo]
' dummy
wait
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #1 on: Oct 26th, 2015, 08:03am » |
|
Figured out the problem! Just needed a little sleep ...
LB is not exactly consistent ...
The difference was in the template that I copied right above the line with the problem. The assignment to the string is different for a combobox and a textbox. The "!" is important.
Code:
[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
if columnType(col) = 0 then
h$ = "#w.tb";row;col
#h$ "!contents? b$"
else
'print #handle.ext, "contents? text$"
h$ = "#w.cb";row;col
#h$ "contents? b$"
end if
print #w.ted, row;":";col;" ";b$
next
next
wait
|
« Last Edit: Oct 26th, 2015, 08:03am by joker » |
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #2 on: Oct 26th, 2015, 08:13am » |
|
The two boxes don't exactly look good combined on the grid.
Apparently the "style" of the borders are different between combo and text boxes.
Perhaps one needs more space than the other.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #3 on: Oct 26th, 2015, 08:41am » |
|
Developed the code for further column box differences with SELECT CASE statements.
Code:
'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell
' Seems to be only for LBB because of "maphandle #w.tb, "#w.tb";row;col"
numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
rowHeight = 20
dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)
columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0
comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"
comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"
cumColumnWidth = 0
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
maphandle #w.tb, "#w.tb";row;col
case 1
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
combobox #w.cb, comboArray$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
maphandle #w.cb, "#w.cb";row;col
case 2
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
combobox #w.cbb, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight
maphandle #w.cbb, "#w.cbb";row;col
end select
cumColumnWidth = cumColumnWidth + columnWidth(col)
next col
cumColumnWidth = 0
next row
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid by Richard Russell" for window as #w
wait
[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
h$ = "#w.tb";row;col
#h$ "!contents? b$"
case 1
'print #handle.ext, "contents? text$"
h$ = "#w.cb";row;col
#h$ "contents? b$"
case 2
'print #handle.ext, "contents? text$"
h$ = "#w.cbb";row;col
#h$ "contents? b$"
end select
print #w.ted, row;":";col;" ";b$
next
next
wait
[validCombo]
' dummy
wait
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #4 on: Oct 26th, 2015, 09:13am » |
|
Oh, and I finally figured out that Code: makes the handle unique in Code:maphandle #w.box, "#w.box";row;col and changed all the handles to the same ".ext".
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Data Grid with Specified Column Widths
« Reply #5 on: Oct 26th, 2015, 09:49am » |
|
You can change the border to the textboxes by adding
stylebits #w.tb, 0, _WS_BORDER,0,0
immediately after case 0,
This is a bit closer in style, but unfortunately, the border for the textbox is still not the same as for the combobox. I'm not sure if you can get exactly the same border for both.
Ray
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #6 on: Oct 26th, 2015, 10:03am » |
|
Thanks, Ray.
I did eventually try that, but it was just as bad (only in a different way!)
I may end up having to add space around each cell.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #7 on: Oct 26th, 2015, 10:48am » |
|
With Ray's addition and added space around the cells.
Curiously, "rowHeight" does not affect the comboBox; only font size affects the height of the comboBox. I don't see any affect of rowHeight on comboBox, but I did not try to change font size. I know what the help says it does, but I didn't see any affect.
Code:
'Last Update: 10/26/2015 5:43:26 AM
' Added space around the cells. pnlawrence
'Last Update: 10/26/2015 4:17:15 AM
' Corrected all the handles to the same "w.cell" pnlawrence
'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell
' Seems to be only for LBB because of "maphandle #w.cell, "#w.cell";row;col"
numberOfRows = 4
numberOfColumns = 5
leftMargin = 5
cellMargin = 5
rowHeight = 20
cumRowHeight = 0 ' define
cumColumnWidth = 0 ' define
dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)
columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0
comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"
comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"
cumColumnWidth = 0
cumRowHeight = 0
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
stylebits #w.cell, 0, _WS_BORDER,0,0 ' trying to make textbox border look like combobox border
textbox #w.cell, leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
maphandle #w.cell, "#w.cell";row;col
case 1
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #w.cell, comboArray$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
maphandle #w.cell, "#w.cell";row;col
case 2
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #w.cell, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col), rowHeight
maphandle #w.cell, "#w.cell";row;col
end select
cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
next col
cumColumnWidth = 0
cumRowHeight = cellMargin + cumRowHeight + rowHeight
next row
cumRowHeight = 0
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid by Richard Russell" for window as #w
wait
[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
h$ = "#w.cell";row;col
#h$ "!contents? b$"
case 1
'print #handle.ext, "contents? text$"
h$ = "#w.cell";row;col
#h$ "contents? b$"
case 2
'print #handle.ext, "contents? text$"
h$ = "#w.cell";row;col
#h$ "contents? b$"
end select
print #w.ted, row;":";col;" ";b$
next
next
wait
[validCombo]
' dummy
wait
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Data Grid with Specified Column Widths
« Reply #8 on: Oct 26th, 2015, 12:09pm » |
|
on Oct 26th, 2015, 09:49am, RNBW wrote:unfortunately, the border for the textbox is still not the same as for the combobox. |
|
Actually on my Windows 10 laptop, running the default theme, the borders do look identical, but the heights are slightly different. Here I can get a good match (with no gaps) as follows:
Code:stylebits #w.tb, 0, _WS_BORDER, 0, 0
textbox #w.tb, leftMargin+cumColumnWidth, row*rowHeight, columnWidth(col), rowHeight+1 Note the rowHeight+1.
on Oct 26th, 2015, 10:48am, pnlawrence wrote:Curiously, "rowHeight" does not affect the comboBox |
|
Whether or not the height value affects the combobox will depend, I think, on whether it's a pre 'Windows XP styles' combobox or a post 'XP styles' combobox (put another way, on what version of the Common Controls library is in use). This is determined by the version of Windows and the contents of the manifest; LBB, and executables compiled by LBB, have a manifest which calls for Common Controls library v6.0.
Richard.
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Data Grid with Specified Column Widths
« Reply #9 on: Oct 26th, 2015, 3:03pm » |
|
Interesting. My laptop is Windows 10 and, using the code without gaps, I got a different border on the textboxes to the comboboxes.
I tried changing the code as Richard suggested in his last post and the horizontal borders were all the same, but the internal vertical borders were all thicker.
However, if you use PNL's code which produces the gaps between the textboxes and comboboxes and use rowHeight+1 for the textbox instead of just rowHeight, it comes out perfectly.
One thing that I don't understand is why the height of comboboxes doesn't change if you change the rowheight.
Ray
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Data Grid with Specified Column Widths
« Reply #10 on: Oct 26th, 2015, 3:13pm » |
|
It's one of those things that you can't see for looking. Richard came up with part of the solution. The rest is to add 1 to the column width for both textboxe and comboboxes. The code below works perfectly for me:
Code:
'Last Update: 10/26/2015 5:43:26 AM
' Added space around the cells. pnlawrence
'Last Update: 10/26/2015 4:17:15 AM
' Corrected all the handles to the same "w.cell" pnlawrence
'Last Update: 10/26/2015 3:35:11 AM
' Developed column types of three. Could be extended. pnlawrence
'Last Update: 10/25/2015 9:01:17 PM
' Working on column types: textbox or combobox. pnlawrence
'Last Update: 10/25/2015 8:23:24 PM
' Added variable width columns. pnlawrence
'Last Update: 10/25/2015 5:43:09 PM
' Adding generic variables for rows/cols/width to original code. pnlawrence
'Last Update: 10/25/2015 7:05:24 AM
' Adapted from textbox grid by Richard Russell
' Seems to be only for LBB because of "maphandle #w.cell, "#w.cell";row;col"
numberOfRows = 4
numberOfColumns = 5
leftMargin = 0
cellMargin = 0
rowHeight = 20
cumRowHeight = 0 ' define
cumColumnWidth = 0 ' define
dim columnWidth(numberOfColumns) ' contains width for each column
dim columnType(numberOfColumns) ' type of box: 0=textbox, 1=combobox1, 2=combobox2
dim comboArray$(numberOfColumns) ' contains data for combo box (needs REDIM for number of items stored)
columnWidth(1) = 75 : columnType(1) = 1
columnWidth(2) = 55 : columnType(2) = 0
columnWidth(3) = 15 : columnType(3) = 0
columnWidth(4) = 55 : columnType(4) = 2
columnWidth(5) = 35 : columnType(5) = 0
comboArray$(1) = "ONE"
comboArray$(2) = "TWO"
comboArray$(3) = "THREE"
comboArray$(4) = "FOUR"
comboArray$(5) = "FIVE"
comboArray2$(1) = "AAA"
comboArray2$(2) = "BBB"
comboArray2$(3) = "CCC"
comboArray2$(4) = "DDD"
comboArray2$(5) = "EEE"
cumColumnWidth = 0
cumRowHeight = 0
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
stylebits #w.cell, 0, _WS_BORDER, 0, 0
textbox #w.cell, cumColumnWidth, cumRowHeight, columnWidth(col)+1, rowHeight+1
maphandle #w.cell, "#w.cell";row;col
case 1
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #w.cell, comboArray$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
maphandle #w.cell, "#w.cell";row;col
case 2
' COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
' COMBOBOX doesn't recognize rowHeight. Height is determined from font size. rowHeight doesn't seem to have any effect.
combobox #w.cell, comboArray2$(), [validCombo], leftMargin+cumColumnWidth, cellMargin+cumRowHeight, columnWidth(col)+1, rowHeight
maphandle #w.cell, "#w.cell";row;col
end select
cumColumnWidth = cellMargin + cumColumnWidth + columnWidth(col)
next col
cumColumnWidth = 0
cumRowHeight = cellMargin + cumRowHeight + rowHeight
next row
cumRowHeight = 0
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid by Richard Russell" for window as #w
wait
[Calc]
#w.ted "!cls"
for row = 1 to numberOfRows
for col = 1 to numberOfColumns
select case columnType(col)
case 0
h$ = "#w.cell";row;col
#h$ "!contents? b$"
case 1
'print #handle.ext, "contents? text$"
h$ = "#w.cell";row;col
#h$ "contents? b$"
case 2
'print #handle.ext, "contents? text$"
h$ = "#w.cell";row;col
#h$ "contents? b$"
end select
print #w.ted, row;":";col;" ";b$
next
next
wait
[validCombo]
' dummy
wait
Ray
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Data Grid with Specified Column Widths
« Reply #11 on: Oct 26th, 2015, 3:47pm » |
|
on Oct 26th, 2015, 3:03pm, RNBW wrote:One thing that I don't understand is why the height of comboboxes doesn't change if you change the rowheight. |
|
As I said before, it depends on the version of the Common Controls library you are using. The supplied height value has never (to my knowledge) affected the size of the non-dropped-down combobox, but when using Common Controls prior to v6.0 (in other words before 'Windows XP Visual Styles') it did affect the height of the dropped-down box.
This could occasionally be useful because you could set the box to display (say) only four items even if there were more in the list. However it confused a lot of people because if set too small it could result in the box appearing not to drop down properly when you clicked on the arrow.
Post Common Controls v6.0 the size of the dropped-down box is determined only by the number of items in the list, I think, and it may be that the supplied height value now has no effect.
If you really wanted to I expect you could get the handle of the combobox's text-box (the GetComboBoxInfo API function returns that) and then explicitly re-size it using (for example) SetWindowPos.
Richard.
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: Data Grid with Specified Column Widths
« Reply #12 on: Oct 26th, 2015, 3:53pm » |
|
Quote:If you really wanted to ... |
|
I'm starting to like the way it has turned out more and more.
I am beginning to convert this to a sub ... I think.
Any ideas on that? Suggestions?
|
« Last Edit: Oct 26th, 2015, 3:54pm by joker » |
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Data Grid with Specified Column Widths
« Reply #13 on: Oct 26th, 2015, 4:17pm » |
|
I presume I am using the common controls prevalent for Windows 10, which I assume is version 6. However, you may be right and the best way to deal with it is to find the hassle of the combobox's text box using an api call. I must start delving into the Windows API. It so often seems to be the way around things with LB.
Ray
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Data Grid with Specified Column Widths
« Reply #14 on: Oct 26th, 2015, 4:19pm » |
|
Sorry about the typo. It should be handle not hassle.
|
|
Logged
|
|
|
|
|