[Gambas-user] Column auto reseize in tables views.
Pino Zollo
pinozollo at ...626...
Sun Aug 2 14:14:08 CEST 2009
Il domenica 2 agosto 2009 05:54:12 Benoît Minisini ha scritto:
> > Il sabato 1 agosto 2009 19:36:51 David Villalobos Cambronero ha scritto:
> > > Hi all,
> > >
> > > How can I automaticly auto resize the column width of my gridview or
> > > tableview. I mean, when I show the view, I want all the columns
> > > adjusted to the cell content.
> > >
> > > Regards
> > >
> > >
> > > --
> > > David
> >
> > You can't automatically. You could write a function
> > to calculate the maximum length of a cell content
> > in the same column and then change the column width.
> > The basic thing is that you have to calculate the width
> > of a cell content. You could do this:
> >
> > Dim iContentW as Integer
> >
> > iContentW = GridView1.Font.Width(GridView1[0,0].Text)
> >
> > Once you have the longest cell content, you can resize that
> > column adding a little value.
> >
> > GridView1.Columns[0].Width = iContentW + 10
> >
> > You have to calculate the width of all cell content of a specific row,
> > select the longest, resize the column. Not comfortable, but not
> > impossible.
> >
> >
> > Bye,
> >
> > Stefano
>
> Normally, setting the column width or row height to -1 does the job, but:
> - It seems to work strangely when the GridView is filled by the Data event.
> - It is not implemented in gb.gtk yet.
>
> Regards,
Recently had been post the following code to resize a table:
---------------------
PUBLIC SUB AdjustGridColumns(pPassedGrid AS TableView)
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
' DEBUG .Current.Text ' <--- always empty
' DEBUG .Font.Width(.Current.Text) ' <--always 0
IF .Font.Width(.Current.Text) > MaxWidth THEN
MaxWidth = .Font.Width(.Current.Text) + 10
END IF
NEXT
' DEBUG $Col, MaxWidth ' <-- always 99
.Columns[$Col].Width = MaxWidth
NEXT
END WITH
END
----------------------------
But here it does not work...
I always get .Current.Text empty.
Any suggestions ?
Ciao
Pino
--
Key ID: 0xF6768208
Key fingerprint = B16D 0A7C 5B29 A334 CE6A 71F6 EAF8 3D88 F676 8208
Key server: hkp://wwwkeys.eu.pgp.net
More information about the User
mailing list