LB Booster
« Data Grid with Specified Column Widths »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:59am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Data Grid with Specified Column Widths  (Read 3356 times)
RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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

User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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                                                                                     
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
« Last Edit: Oct 26th, 2015, 12:24pm by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
« Last Edit: Oct 26th, 2015, 3:50pm by Richard Russell » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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. wink wink wink

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 » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: Data Grid with Specified Column Widths
« Reply #15 on: Oct 26th, 2015, 4:25pm »

Perhaps you had a little Freudian slip? cheesy

on Oct 26th, 2015, 4:19pm, RNBW wrote:
Sorry about the typo. It should be handle not hassle.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
« Last Edit: Oct 27th, 2015, 09:39am by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx 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
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls