|
-
Mar 27th, 2013, 02:31 PM
#1
Thread Starter
Addicted Member
Programmatically set dimensions of MSFlexGrid based on columns/rows
I've found a few answers to this on the net but nothing is very accurate. Some leave scrollbars and others leave gray background area. I'm using VB6 and an MSFLexGrid control.
This is the basic code for setting up the grid
Code:
with grid
.cols=3
.ColWidth(0) = 400
.Row = 0
.Col = 1
.ColWidth(1) = 800
.Col = 2
.ColWidth(2) = 0
end with
Code:
For X = 0 To .Cols - 1
.Width = .Width + (.ColWidth(X) + Screen.TwipsPerPixelX))
Next
- and -
For X = 0 To .Rows - 1
.Height = .Height + (.ColHeight(X) + Screen.TwipsPerPixelY))
Next
That's the basic routine I'm using. It is not very accurate. For the width, for instance, it leaves horizontal scroll bars.
However, if I add the line
Code:
.Width = .Width + 23
- and -
.Height = .Height-140
to the end of the code, the scroll bar disappears.
Overall I'm using about 10 MSFlexGrids in my project and find the calculations differ on each table depending on the number of rows and columns each has. I have not adjusted the height of any rows so they remain at the default (240).
Oddly enough, when I step through the column calculations the .ColWidth(x) set at 400 comes out reading '405" and the one set to 800 reads '795" ... ???
Surely there must be a consistent way to accurately figure the dimensions?
TIA
Ken
-
Mar 27th, 2013, 07:01 PM
#2
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Mar 27th, 2013, 07:16 PM
#3
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Those dimensions are in Twips but must come out to a whole number of the equivalent in pixels, which varies by the current DPI setting you have for the display. If you use an "off" size it gets rounded to the nearest pixel.
-
Mar 28th, 2013, 04:07 AM
#4
Thread Starter
Addicted Member
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
I haven't tried that code JG .. but thanks for sharing. From what I gather from the responses here, it seems odd to me that you can resize columns to fit an oversize grid but not fit the grid to existing columns. I decided to redesign all the forms in my project based on a lower screen resolution rather than fight with the resizing. I had been using listboxes extensively and found I used half or even less the amount of code by using MSFlexGrids instead ... and things look better -with the exception of having to fiddle with fixing the height and width. If the code works I'll come back and mark the thread as resolved although it's sort of a backwoods workaround ...
Thanks for replying dilettante. From what you are saying I gather there is no way to determine the screen resolution and adjust the grid size based on that. So my method of adding to the dimensions by using an arbitrary number seems the only way to go. Oh well .. it is what it is and all we can do is work within the limitations. Thanks again.
-
Mar 28th, 2013, 10:49 AM
#5
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Don't forget that you need to allow for grid line width when adding up your column widths. Try with a large grid line width and you'll see....
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Mar 28th, 2013, 11:28 AM
#6
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
What Colin said...
That was my first thought too... not only between the cells but also the border around the grid itself too... when you set the width of a cell, it sets the inside width... assuming that all measurements are in px (which I know they aren't in VB6, but for argument sake we'll jsut roll with it) if the border width is 1px... and the cell is 200px... the total width of the cell is 202... 1px for left and 1px for the right, plus the inside 200px... and since the text doesn't just slam right up against the border, there's an internal margin too... not sure if that's part of the 200px as well, or if it adds to it....and the left 1px border is the right 1px of the cell before it... so...ya know...
-tg
-
Mar 28th, 2013, 02:08 PM
#7
Thread Starter
Addicted Member
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Thanks guys .. in the end the only way seems to just add a figure to the width/height as I did. I was aware of the line width which is why I was adding something to the grid.width. I found that adding 23 to the width removed horizontal scroll bars and anything less left them in place.
JG - that code did not work out for me at all - I couldn't get it to run ... when entering the call to the sub VB kept telling me I had to set the call = something. In other words I could not simply call the subroutine like I do every other one. No biggie .. I'll just go on adding numbers to force the grid into it's gridbox without scroll bars.
Ken
-
Mar 28th, 2013, 02:29 PM
#8
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
OK, but if your users have their scrollbars set to anything other than the default size then your 'magic' 23 will not be so magic after all...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Mar 28th, 2013, 03:13 PM
#9
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Been playing around with this as it should (you'd imagine!) be simple.
Anyway, if you have a flat grid with no borders, then take the sum of all .ColWidths and size the grid to that total, you will find that you will always have to add one pixel (15 twips) to the flexgrid's width in order to make the scrollbar go away. This one pixel appears to relate to a border that you can see but can't make go away via any of the controls properties.
Therefore, to solve your problem, you need to allow for;
1) the size of the border that is drawn when the control is 3D as opposed to flat (or put it inside a picture box and use the pictures border for that 3d look)
2) allow for that one pixel described above
3) allow for the size of the scrollbar which you can obtain via a GetSystemMetrics API call
This should fix ya...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Mar 28th, 2013, 03:15 PM
#10
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Oh, and the grid line width is NEVER a factor, to my surprise...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Mar 28th, 2013, 03:18 PM
#11
Re: Programmatically set dimensions of MSFlexGrid based on columns/rows
Another solution - to heck with sizing the grid... jsut let the form dictate the size and if there's scrollbars... so be it...
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|