[Gambas-user] column width in gridview
Rolf-Werner Eilert
eilert-sprachen at ...221...
Wed Jun 4 18:04:16 CEST 2008
Peter Mathijssen schrieb:
> Hi,
>
> With this code i can set the width of the columns.
>
> WITH GridView1
> .Columns.Count = 2
> .Rows.Count = 0
> .Columns[0].Width = 250
> .Columns[0].Text = lblcommand.Text
> .Columns[1].Width = 500
> .Columns[1].Text = lbldescription.Text
>
> END WITH
>
> When i don't set the column width i get a small first column and a second
> column that is large enough to hold the whole text.
>
> But when i use the columns.width property i always get a smaller second
> column. So not all text is displayed.
>
> I tested a little. I seems that as long as i set the width of the second
> column smaller then the width of the first one i can set it's width. Is the
> width of the second column larger then that of the first one it doesn't
> work.
>
> If i only set the width of the first column, the second one gets the same
> width.
>
> Does anyone has this too?
>
> Peter
Yes, at least very similar.
In my application, I set the column widths dynamically (my idea was to
adapt them to the largest text width contained in each column). So what
I do is collecting the maximum text width for each column in an array
from within the data event (just one line needed here), the gridview
here is called "tb", the array is tbBreite[]:
PUBLIC SUB tb_Data(Row AS Integer, Column AS Integer)
[lots of things to do...]
IF tb.Font.Width(feld[Column]) > tbBreite[Column] THEN
tbBreite[Column] = tb.Font.Width(feld[Column])
END
So after filling the grid, each column width is known, and then I can do
this in the SUB that calls the whole thing:
tb.Rows.Count = liste.Count 'this will call tb_Data
FOR i = 0 TO 6
tb.Columns[i].Width = tbBreite[i] + 10
NEXT
In fact, this runs well in most cases, BUT... :-)
- the gridview is on a tabview, and if the tabview shows another tab
than the gridview I try to adjust the columns in, this will NOT
function. So I have to say tabview.index = 0 or 1 or whatever to make
for example "tb" appear on screen BEFORE I call tb.Rows.Count = ...
Strange though because it fills with text anyway.
- sometimes, and this is not on a reproduceable basis, this doesn't run
either! So sometimes, all columns just stay very narrow, and there is
really no reason to be seen for this.
- and sometimes the last column (I have more than 2, sometimes 6,
sometimes 4) will be as large as to the end of the gridview (right
edge), sometimes it stays smaller and leaves a blank area at the right.
When one of the columns is wide enough, the horizontal scroller will
appear and the whole gridview is wide. But when it stays smaller
(whether by error or correctly if there is just no more text), it is not
predictable what will happen to the rightmost column.
- this seems to be specific to Gambas 2. I have done this many times in
Gambas 1, and have never had this problem.
I guess this won't really help you on, but you're not alone with the
column width problem I guess :-)
Rolf
More information about the User
mailing list