Solved

MSFlexGrid Double-Click Column Resize

Posted on 2006-10-23
4
1,348 Views
Last Modified: 2013-12-25
Hi.  Could you please tell me how to make an MSFlexGrid control resize a column to display the longest text in that column when the user double clicks when the double-arrowed mouse cursor appears between column boundaries?  Thank you.
0
Comment
Question by:deatc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 17792606
You could do it by adding an invisible autosizing label to your form. If you populate it with every value in the flexgrid column and take the largest width this will be the width of the largest column. Also make sure that the fonts in both controls match.

Have you thought of using a listView control instead? It is default behaviour in a listView control.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17794287
Try this (click the column header) :
========================

Needs:
1 Form
1 Flexgrid  (Hit Ctrl-T ---> Microsoft Flexgrid Control 6.0)



Private Sub Form_Activate()
WindowState = 2: MSFlexGrid1.Move 0, 0, 15 * 400, 15 * 150
   
    MSFlexGrid1.Cols = 5
    MSFlexGrid1.Rows = 1
   
Me.MSFlexGrid1.TextMatrix(0, 1) = "col_1"
Me.MSFlexGrid1.TextMatrix(0, 2) = "col_2"

Call newRow("Bill")
Call newRow("Gates")
Call newRow("Windows")
Call newRow("XP")
End Sub




Sub newRow(ByVal ns As String)
    Me.MSFlexGrid1.AddItem ns
    Me.MSFlexGrid1.Row = MSFlexGrid1.Rows - 1

For r = 1 To Me.MSFlexGrid1.Cols - 1
    Me.MSFlexGrid1.Col = r
    Me.MSFlexGrid1.Text = String(8 * Rnd, 65)
Next

End Sub



 
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim MaxTextWidth As Long, M
For r = 1 To Me.MSFlexGrid1.Rows - 1
    MSFlexGrid1.Row = r
    M = (MSFlexGrid1.Text)
    If TextWidth(M) > MaxTextWidth Then MaxTextWidth = TextWidth(M)
Next
    MSFlexGrid1.ColWidth(MSFlexGrid1.Col) = MaxTextWidth
End Sub
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 17794321
correction :
=======

instead ...

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim MaxTextWidth As Long, M
For r = 1 To Me.MSFlexGrid1.Rows - 1
    MSFlexGrid1.Row = r
    M = (MSFlexGrid1.Text)
    If TextWidth(M) > MaxTextWidth Then MaxTextWidth = TextWidth(M)
Next
    MSFlexGrid1.ColWidth(MSFlexGrid1.Col) = MaxTextWidth
End Sub

use this :
=======

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If y > MSFlexGrid1.RowHeight(0) Then Exit Sub
Dim MaxTextWidth As Long, M
For r = 1 To Me.MSFlexGrid1.Rows - 1
    MSFlexGrid1.Row = r
    M = (MSFlexGrid1.Text)
    If TextWidth(M) > MaxTextWidth Then MaxTextWidth = TextWidth(M)
Next
    MSFlexGrid1.ColWidth(MSFlexGrid1.Col) = MaxTextWidth
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 60
RUNRMTCMD from AS/400 12 86
VBA: loop recent folder and copy txt file. 8 49
transition to visual .net from vb6 5 59
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question