deatc
asked on
MSFlexGrid Double-Click Column Resize
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.
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(MSFle xGrid1.Col ) = MaxTextWidth
End Sub
========================
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(
Me.MSFlexGrid1.TextMatrix(
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
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(MSFle
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you thought of using a listView control instead? It is default behaviour in a listView control.