[Gambas-user] GridView adjust column length

Stephen Bungay sbungay at ...981...
Fri Jul 3 19:19:57 CEST 2009


Try this (from my GridUtils Class.. can't believe that was written 3 
years ago now!)

'***********************************************************************
'* AdjustGridColumns
'* Author: Stephen Bungay
'* Date: July 26 2006
'*
'* Parameters:
'*   GridView
'*
'* Calls: Nothing
'*
'*   Adjusts the column sizes of the gridview being used for data
'* presentation. Ensures that all of the data is visible.
'*
'**************************************************************************
PUBLIC SUB AdjustGridColumns(pPassedGrid AS GridView)

   DIM $Row AS Integer
   DIM $Col AS Integer
   DIM MaxWidth AS Integer

   MaxWidth = 0

   WITH pPassedGrid
       .Columns.Resizable = TRUE
       FOR $Col = 0 TO .Columns.Count - 1
           .Row = 0
           .Column = $Col
           MaxWidth = .Current.Width

           FOR $Row = 0 TO .Rows.Count - 1
               .Row = $Row
               IF .Font.Width(.Current.Text) > MaxWidth THEN
                  MaxWidth = .Font.Width(.Current.Text) + 10
               END IF

           NEXT
           .Columns[$Col].Width = MaxWidth
       NEXT

   END WITH
END


Dan Sheffner wrote:
> I'm filling a very simple GridView with the below code but I cannot adjust
> the column length.  I have resizable set to TRUE and I have also tried to do
> GridView1.resizable = TRUE after the grid is populated with the values.  Am
> I missing something or using the wrong property?  Also is there an auto
> length to make sure the whole column is visiable?  Thanks in advance.
> 
> FOR EACH sb IN arrayOfLines
>     sb = Trim(sb)
>     'PRINT sb
>     arrayOfSpaces = Split(sb, " ")
>     GridView1[rowCount, 0].Text = arrayOfSpaces[0]
>     GridView1[rowCount, 1].Text = arrayOfSpaces[1]
> 
> 
> at the bottom of the SUB:
> 
> GridView1.Resizable = TRUE
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 




More information about the User mailing list