StefanD
asked on
Autosize columns in an a (hierarchical) flexgrid
Hi all,
I want my Flexgrid to automatically size the columns to the content in the columns when the user double clicks on the separator on the top row of the flexgrid. In other words: same behavior as Excel.
thanks,
Stefan
I want my Flexgrid to automatically size the columns to the content in the columns when the user double clicks on the separator on the top row of the flexgrid. In other words: same behavior as Excel.
thanks,
Stefan
ping...
This snippet is not perfect, there is no specific event for clicking/ dblclicking on the sizing handle for the column, the event will fire when the header row is dblclicked. It also relies on having the same font (inc size) used by default on the form and in the grid. If there are different fonts on the grid then this can be handled as well but requires some slight modification.
Private Sub MSFlexGrid1_DblClick()
Dim dblWidth As Double
Dim intCol As Integer
Dim intRow As Integer
intRow = MSFlexgrid1.MouseRow
intCol = MSFlexgrid1.MouseCol
If intRow = 0 Then 'Clicked on header row
For intRow = 1 To MSFlexGrid1.Rows - 1
If Me.TextWidth(MSFlexGrid1.T extMatrix( intRow, intCol)) > dblWidth Then
dblWidth = Me.TextWidth(MSFlexGrid1.T extMatrix( intRow, intCol))
End If
Next
MSFlexGrid1.ColWidth(intCo l) = dblWidth + 100
End If
End Sub
Private Sub MSFlexGrid1_DblClick()
Dim dblWidth As Double
Dim intCol As Integer
Dim intRow As Integer
intRow = MSFlexgrid1.MouseRow
intCol = MSFlexgrid1.MouseCol
If intRow = 0 Then 'Clicked on header row
For intRow = 1 To MSFlexGrid1.Rows - 1
If Me.TextWidth(MSFlexGrid1.T
dblWidth = Me.TextWidth(MSFlexGrid1.T
End If
Next
MSFlexGrid1.ColWidth(intCo
End If
End Sub
ASKER
Thanks for your post, but I really need to know whether the user doubleclicked on the sizing handle. The column headers are already used for sorting data in that column.
Stefan
Stefan
Stefan, this is not what you asked in first place!
ASKER
I tried to make clear I wanted to know whether a user double clicked on the separator between two columns. I just didn't know that it's called a sizing handle. I thought the 'just like excel' part made things clear, but apperntly it didn't. Sorry.
Stefan
Stefan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Indeed, a working solution. This code does exactly what I was looking for. Thank you very much, you deserved the points.
Stefan.
Stefan.