[Gambas-user] GridView Cell Height with WordWrap

Gianluigi bagonergi at gmail.com
Mon Mar 1 11:14:47 CET 2021


Hi Rolf,
I thank you for the question about the _GridView_Cell.WordWrap property
which allowed me to go deeper into the subject.
I would like to make a couple of considerations with you.

First of all, I would avoid looping the rows directly in the Form_Open()
routine, as I wrongly proposed, because it forces to read all the cells and
therefore if you have many columns it slows down the code.
If you want to use GridView_Data, better if you cycle the column where
WordWrap is useful in the Sub Form_Activate(), if desired, it also allows
you to show a ProgressBar.

But, with WordWrap, I would also avoid using the GridView_Data routine
because this routine is primarily meant for large amounts of data and in
this case it is best to avoid WordWrap and rely on GridView.Columns.Width =
-1.

In summary, if you have little data you can use WordWrap such as:
'-----------------------------------------
Public Sub Form_Open()

  With GridView1
    .Header = 3
    .Columns.Count = 2
    .Columns.Width = 100
    .Rows.Count = 100
  End With
  For r As Integer = 0 To GridView1.Rows.Max
    For c As Integer = 0 To GridView1.Columns.Max
      If r Mod 2 = 0 Then
        GridView1[r, c].Background = &HBFFFBF
        GridView1[r, c].Text = "Liber tempor"
      Else
        GridView1[r, c].WordWrap = True
        GridView1[r, c].Text = "Lorem ipsum dolor sit amet, consectetuer
adipiscing elit, sed diam nonummy."
      Endif
    Next
    GridView1.Rows[r].Height = -1
  Next

End
'-----------------------------------------

If you have a lot of data, use GridView_Data and Columns.Width such as:
'-----------------------------------------
Public Sub Form_Open()

  With GridView1
    .Header = 3
    .Columns.Count = 2
    .Rows.Count = 100
    .Columns.Width = -1
  End With

End

Public Sub GridView1_Data(Row As Integer, Column As Integer)

  If Row Mod 2 = 0 Then
    GridView1.Data.Text = "Lorem ipsum dolor sit amet, consectetuer
adipiscing elit, sed diam nonummy."
  Else
    GridView1.Data.Text = "Liber tempor"
    GridView1.Data.Background = &HBFFFBF
  Endif

End
'-----------------------------------------

In the hope of not having written some nonsense
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210301/5b1f8ed5/attachment.htm>


More information about the User mailing list