-
Jan 23rd, 2002, 04:05 PM
#1
MSFlexgrid - Set column width to text width..
How do I set the column width to be = to the amount of text
(the text length varies)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 23rd, 2002, 04:25 PM
#2
Hyperactive Member
Very good question.
Although I've never tried the way I'd approach is:
Check all Rows for Largest number of Characters
Use Length of that word to and then You need to
Figure out the Twips per Character.
I've only seen Twips Per Pixel so I'm not sure where to
go from here.
-
Jan 23rd, 2002, 04:38 PM
#3
thats what im doing...
but ..the TextWidth() command isnt quite enough
it comes up with 1125 for one col where the column needs about 1400 to fit it...
hmmm...
thanks
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 23rd, 2002, 04:41 PM
#4
nevermind..now that I removed the cellfontbold = true... it works
the bold was messing up the textwidth()
thanks
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 23rd, 2002, 04:42 PM
#5
Here is a Generic routine I've put together a while back:
VB Code:
Public Sub ResizeGrid(pGrid As MSFlexGrid, pForm As Form)
Dim intRow As Integer
Dim intCol As Integer
With pGrid
For intCol = 0 To .Cols - 1
For intRow = 0 To .Rows - 1
If .ColWidth(intCol) < pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100 Then
.ColWidth(intCol) = pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100
End If
Next
Next
End With
End Sub
Then just call this routine like this:
ResizeGrid MSFlexGrid1, Form1
-
Jan 23rd, 2002, 05:06 PM
#6
similar to what I did..
But.. As I added each row...I checked...if the textwidth + 100 > current column width the make the colwidth = textwidth + 100
only problem is some of the cols have to be bold. Im working on a solution...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 16th, 2004, 11:20 AM
#7
Hyperactive Member
This seemed to work for me. Scrolling through every cell in that column, finding the max Twip size and then adjusting the cell for the max size:
Private Sub mnuAdjust_Click(Index As Integer)
Dim i As Integer
Dim maxTwips As Integer
Dim Twips As Integer
With Me.MSFlexGrid1
Me.ScaleMode = vbTwips
For i = 0 To .Rows - 1
Twips = Me.TextWidth(.TextMatrix(i, .ColSel))
If Twips > maxTwips Then
maxTwips = Twips
End If
Next i
.ColWidth(.ColSel) = maxTwips * Me.MSFlexGrid1.Font.Size / Me.Font.Size + 100 '* Screen.TwipsPerPixelX
End With
End Sub
Thanks for the help.
-
Jul 16th, 2004, 12:28 PM
#8
Originally posted by geoff_xrx
similar to what I did..
But.. As I added each row...I checked...if the textwidth + 100 > current column width the make the colwidth = textwidth + 100
only problem is some of the cols have to be bold. Im working on a solution...
When using TextWidth, it uses the Font settings of the object - your form in this case. If you set your form's font settings to the same as the font settings of the col you are trying set the width on, you'll get the right numbers.
TG
-
Aug 6th, 2017, 01:34 PM
#9
Addicted Member
Re: MSFlexgrid - Set column width to text width..
This is a very old thread, but some beginners would still like to know an easier method:
Place the MSFlexGrid on the form
Double-click on it
It will automatically opened in the _Click Section. In the right-hand list box, select EnterCell
Write or paste the following code:
Me.Caption = MSFlexGrid.CellWidth
In the properties of the toolbox, make sure the following is set:
AllowUserResizing to 1-FlexResizeColumns
Run the program.
Now you can drag the column width to your choice, and the width when you click on the column will be reflected in the form's caption. Write it down to place it in the code part of your prg.
Example (for column1 [[2]]):
~~~~~~~~~~~~~~~~~~
MSFlexGrid.ColWidth(1) = 1410
To quickly set headers, you can use this property:
' Set column and row headers.
s$ = "|Name|Address|Telephone|Social Security#"
s$ = s$ + ";|Robert|Jimmy|Bonzo|John Paul"
MSFlexGrid.FormatString = s$
but, it will not set the widths. It all depends on the font you use, with formatting set etc. So it's easier to do it in the above drag-method.
Hope it helps.
When in windows 10, the help system does not work, but when you run the winhelp32.exe program, you can click on File (alt+f), open. And it will run the .HLP file.
Copy from windows XP:
[drive]:\windows\winhlp32.exe
to a folder of your choice
Right click on the file, properties (at the bottom of the list)
Compatibility Tab
Run as XP ServicePack 2
The MSDN help files are still saved under the.CHM extention, which will open in windows 10:
Under the MSDN section on your VB6 disc, goto:
\msdn\
where you will find the file:
MSHFLX98.CHM
There are more help files in the same folder.
Enjoy.
-
Aug 6th, 2017, 03:12 PM
#10
Re: MSFlexgrid - Set column width to text width..
When in windows 10, the help system does not work,
Obviously you do not know how to install it properly. Check on this Forum and you will find out how to make it work (if yours does not)!!!
As for the autosizing of width of Flexgrids, see this Planet link (for YOU and for all of the folks who haven't figured it out in the past 13 years!!!!) ~smile~
http://www.planetsourcecode.com/vb/s...=8547&lngWId=1
-
Aug 6th, 2017, 05:28 PM
#11
Re: MSFlexgrid - Set column width to text width..
To be fair there is a big glitch with the parts of Help that are based on the older WinHelp technology.
When you try to use those you'll often get an error dialog and your default browser gets opened to a Microsoft page saying "sorry, suck wind."
That's because so far they have not released a WinHelp install package for Windows 10. We had them for Vista, Win7, Win8, and maybe even Win 8.1 and Win8.1 Fire Two, but not for Windows 10.
A few people have posted hacked versions of the Win7 or Win8 packages that bypass the version check and supposedly those will work. I'm still digging in my heels though, there is no reason to let Microsoft off the hook for this. "Bathless" Anders "VB Killer" Hejlsberg and his gang of cronies needs to be opposed at every turn. Post as much noise as you can about this through comments on MSDN and MS KB pages.
-
Aug 7th, 2017, 06:02 AM
#12
Re: MSFlexgrid - Set column width to text width..
Here is another example of sizing Cols to width of text -
http://www.vb-helper.com/howto_fit_flexgrid.html
-
Aug 7th, 2017, 09:42 AM
#13
Addicted Member
Re: MSFlexgrid - Set column width to text width..
Originally Posted by SamOscarBrown
Obviously you do not know how to install it properly. Check on this Forum and you will find out how to make it work (if yours does not)!!!
My VB was installed on Win 7 where it worked correct. Then I upgraded to windows 10, therefore I have struggle, but I do not really care.. :-)
As for the autosizing of width of Flexgrids, see this Planet link (for YOU and for all of the folks who haven't figured it out in the past 13 years!!!!) ~smile~
http://www.planetsourcecode.com/vb/s...=8547&lngWId=1
I do not really use the flexGrid, but like to play with a lot of things. Yes, I'm still a bit stupid after 13 years ha ha ha
Thanx 4 the q reply
-
Aug 7th, 2017, 10:08 AM
#14
Addicted Member
Re: MSFlexgrid - Set column width to text width..
The biggest problem when adding a fixed size after the width, (automatic width estimation) comes when the user/programmer use different fonts (think courier, Sans etc) and sizes.
Therefore I still believes the programmer have an easier task to drag the width and make the width a fixed size.
But each of us have their own perceptions and ideas. In reality, there's not a right or wrong answer. It's what's easier for each programmer.
And above all, I'm too lazy to write a huge piece of code to do a simple heading, unless writing a user control, and I'm far too stupid to write one anyway.
[Edited]
Here is a small, very confused piece of code I wrote (compiled):
http://thezir.com/GTScode/QLaw.exe
Last edited by Inside; Aug 7th, 2017 at 10:15 AM.
Reason: Adding Info
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
|