Re: MSFlexGrid InFlexible
- From: "Bert van den Dongen" <bertdon@xxxxxxxxxx>
- Date: Mon, 10 Mar 2008 23:31:32 +0100
My code produces a width of 4845 on my own machine, and it displays the grid
with the first six coumns displayed exactly, each displaying its own vertical line at the right side. In more detail, if I use it on an MSFlexGrid with a BorderStyle of zero it produces a grid which is exactly 317 pixels wide (300 for the six columns plus 17 for the scrollbar), which on my own standard 96 dpi (15 twips per pixel) is 317 x 15 = 4755. The result returned by MSFlexGrid1.Width is also exactly 4755 twips.
With BorderStyle = 0 I have exactly the same: 4755.
If on the other hand I run it on an MSFlexGrid with a BorderStyle of 1 it produces a grid which is exactly 323 pixels wide (300 for the six columns plus 17 for the scrollbar plus 6 for the overall width of the borders), which on my own standard 96 dpi machine is 323 x 15 = 4845 twips. The result returned by MSFlexGrid1.Width is also exactly 4845 twips.
With BorderStyle = 1 I have 4815 (60 more for the borders),
where you have 4845 (90 more for the borders).
So in both cases the result returned by the Width property is exactly the same as the actual overall width and in both cases the view of the grid shows exactly six columns, with all columns including the last one displaying its vertical line at the right side
Absolutely, both looks are correct.
I am surprised, however, that my calculation of
4815 twips gave a wrong result with you . . .
That's because 4815 is too small on my machine, probably because the overall width of the MSFlexGrid borders is different on my machine than it is on yours, most probably because I am running Vista. The overall borders come to 6 pixels on my own machine, and probably 4 pixels on yours. So, as you will see, the code I posted produces exactly the desired output, automatically taking into account any little differences between one machine and the next.
Yes Mike, totally agreed.
I'm happy with the fact that your code determines the Width
of the grid, where I always have to consider the adding of
60 twips (which is not flexible at all), but when I set the
MSFlexGrid1.Cols = 6 (while still visColumns = 6) it did
show a horizontal scrollbar which not logical because all
columns are shown. I think that bar should only be visible
when there are more columns in the grid then are shown.
It appears to be a little idiosyncracy of the MSFlexGrid control which apparently omits the horizontal scrollbar only the required client width to display all columns is_less_than the available client width (at least that's the logic it appears to use). Obviously the common sense thing for the MSFlexGrid to do would be to omit the scroll bar if the required client width is less_than_or_equal_to the available client width, but it doesn't seem to be doing the sensible thing :-(
I think so too.
The solution is to add one extra pixel to the overall calculated size when you wish to display all columns exactly. In such a case of course it would be nice to set BackColorBkg to the same as ForeColorSel to make it look nice. So when displaying all columns exactly you would change the line:
.Width = ScaleX(xBorders + visColumns * 50, vbPixels, _
.Container.ScaleMode)
. . . to:
.Width = ScaleX(xBorders + visColumns * 50 + 1, vbPixels, _
.Container.ScaleMode)
So I did and yes, the horizontal scrollbar is gone now.
One other thing is that in reality all columns in my grids have
different colWidths, tailormade to the data to be displayed
so counting remains necessary. Nevertheless, your code is
a definite improvement.
Yep. Counting up all the desired widths is still a necessity in such cases, but once they are counted up the code will ensure that all columns will display exactly, regardless of the various differences in settings on various machines (as you can see by the fact that the code automatically displayed exactly six of the 20 column widths both on your machine and on my own, even though they are apparently using different overall border widths. In fact for stuff such as tailormade column widths (as you have said you often use) you could probably change the code into a function to which you pass an array of integers (as many elements as their are columns) and have the function deal with that data.
Mike
Yes, that is definitely the best solution.
I already implemented David Youngblood's solution for determining
the width of a scrollbar via GetSystemMetrics in one of my projects,
but with your suggestion I can forget about both this scrollbar-width
and the extra 60 twips. Great code, system-independent.
Thanks a lot Mike (and Rick and David).
Bert.
.
- References:
- Re: MSFlexGrid InFlexible
- From: Mike Williams
- Re: MSFlexGrid InFlexible
- From: Bert van den Dongen
- Re: MSFlexGrid InFlexible
- From: Rick Rothstein \(MVP - VB\)
- Re: MSFlexGrid InFlexible
- From: Bert van den Dongen
- Re: MSFlexGrid InFlexible
- From: Mike Williams
- Re: MSFlexGrid InFlexible
- From: Bert van den Dongen
- Re: MSFlexGrid InFlexible
- From: Mike Williams
- Re: MSFlexGrid InFlexible
- From: Bert van den Dongen
- Re: MSFlexGrid InFlexible
- From: Mike Williams
- Re: MSFlexGrid InFlexible
- Prev by Date: Re: ListView Crashing
- Next by Date: File not found: 'C:\WINDOWS\system32\ieframe.dll\1'
- Previous by thread: Re: MSFlexGrid InFlexible
- Next by thread: Re: MSFlexGrid InFlexible
- Index(es):
Relevant Pages
|