VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon

by Vinit Malshe (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th January 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon The Maximum Length Of The Text In Each Row

API Declarations


'IMPORTANT: - The Font Property Of The Form And The Grid Control Must Be Same.

Rate The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon




'''''''''''''''''''''''''' Start From This ''''''''''''''''''''''''''''''''

gridtitles = Array("Customer ID", "Name", "Address", "Telephone No")
Call InitGrid(MSFlexGrid1, 1, 4, gridtitles)

'''''''''''''''''''''''' Upto This ''''''''''''''''''''''''''''''''''''''''



Sub InitGrid(msflexName As Control, rowCount As Integer, ColCount As Integer, ColArray)

If (TypeOf msflexName Is MSFlexGrid) Or (TypeOf msflexName Is MSHFlexGrid) Then
   With msflexName
     .Rows = rowCount
     .Cols = ColCount
             
     For i = 0 To ColCount - 1
         .TextMatrix(0, i) = ColArray(i)
     Next
   End With
End If
End Sub




Sub NewColumnWidth(FlexGridName As Control, frmName As Form)
'Width of the current column gets increased depending upon the maximum length of 'the text present in that column
 
Dim i, j, columnwidth As Integer

columnwidth = 0

If (TypeOf FlexGridName Is MSFlexGrid) Or (TypeOf FlexGridName Is MSHFlexGrid) Then
   With FlexGridName
        For j = 0 To .Cols - 1
            For i = 0 To .Rows - 1
                If columnwidth < frmName.TextWidth(Trim(.TextMatrix(i, j))) Then      
                   columnwidth = frmName.TextWidth(Trim(.TextMatrix(i, j))) 
                endif
            Next

            .ColWidth(j) = columnwidth + 100
            columnwidth = 0
        Next
   End With
End If
End Sub


Download this snippet    Add to My Saved Code

The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon Comments

No comments have been posted about The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon. Why not be the first to post a comment about The Width Of The Columns Of The FlexGrid/MSFlexGrid/MSHFlexGrid Control Get Adjusted Depending Upon.

Post your comment

Subject:
Message:
0/1000 characters