[Gambas-user] GridView.ClientWidth yields incorrect size on Form_Open

Gianluigi bagonergi at gmail.com
Sun Feb 3 10:48:21 CET 2019


Il giorno dom 3 feb 2019 alle ore 00:25 T Lee Davidson <
t.lee.davidson at gmail.com> ha scritto:

> On 2/2/19 5:05 PM, Gianluigi wrote:
> > If with "Charlie" you're referring to me, also me can not get Expand to
> work.
> > But I think you can easily replace it with Width = -1
>
> Actually, no Gianluigi, I was not referring to you. I thought the code you
> first presented was directed toward someone else.
>

yes, I was talking to Denis.
But I see no answers from Charlie in this discussion.


> As far as I understand the two, GridView_Column.Expand cannot be easily
> replaced with .Width = -1. The latter causes the width
> of the column to be resized according to the optimum width for the _data_
> in the column. Whereas, .Expand works in relation to
> the combined width of the other columns and the .ClientWidth.
>
> I can achieve what I am wanting with:
>
> [code]
> Private iFixedColumnsWidth As Integer = 0
>
> Public Sub Form_Open()
>
>    Dim Headers As String[] = ["0123456789", "0123456789", "0123456789",
> "0123456789"]
>
>    With GridView1
>      .AutoResize = False
>      .Header = GridView.Horizontal
>    End With
>
>    GridView1.Rows.Count = 1
>    GridView1.Columns.Count = Headers.Count
>    For i As Integer = 0 To Headers.Max
>      GridView1.Columns[i].Title = Headers[i]
>      iFixedColumnsWidth += GridView1.Columns[i].Width
>    Next
>    iFixedColumnsWidth -= GridView1.Columns[0].Width
>
> End
>
> Public Sub GridView1_Arrange()
>
>    GridView1.Columns[0].Width = (GridView1.ClientWidth -
> iFixedColumnsWidth)
>
> End
> [/code]
>
> But not with the Expand property.
>
>
> ___
> Lee
>

Now I understand what you mean and this should work:

Public Sub Form_Open()

  Dim Headers As String[] = ["0123456789", "0123456789", "0123456789",
"0123456789"]

  With GridView1
    .AutoResize = True
    .Header = GridView.Horizontal
  End With

  GridView1.Rows.Count = 1
  GridView1.Columns.Count = Headers.Count
  For i As Integer = 0 To Headers.Max
    GridView1.Columns[i].Title = Headers[i]
    GridView1[0, i].Text = String(30, "*")
  Next
   GridView1.Columns[0].Expand = True
   GridView1.Columns[1].Expand = True
   GridView1.Columns[2].Expand = True
   GridView1.Columns[3].Expand = True
   'GridView1.Columns[0].Width = -1

End

Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190203/d736ab16/attachment.html>


More information about the User mailing list