B4A Library [Class] Flexible Table

dwsands

Member
Licensed User
you can do that via the callback function which was extended by Klaus for me.
Wwithin the callback function you can change every cell as you like - be aware that it might change the column width and it is not possible to rearrange that by a call from within the callback function (this would trigger a repaint of the table and so an endless-loop)

e.g. italic to every 2nd row:
Sub Table1_ShowRow(Row As Int, lbls() As Label)
    If Row Mod 2 = 0 Then
    For i = 0 To lbls.Length -1
        lbls(i).Typeface = Typeface.CreateNew(Main.myFont, Typeface.STYLE_ITALIC)
    Next
    End If
End Sub
Attached an example of my app: coloring every cell depending on different values, played games etc.
Thank you!!!!!

Now your probably going to laugh at this question, but the "Main.myFont" gives an "Undeclared variable..." error. The module and the layout are named Main so I'm stuck, help.
 

Kanne

Member
Licensed User
the first parameter is a variable of type Typeface which is declared in my main-module.
You may also use any constant from B4X instead, e.g.
Typeface.SERIF
or
Typeface.SANS_SERIF
.
So the statement may look something like this (for using the font sans_serif with style italic):
B4X:
lbls(i).Typeface = Typeface.CreateNew(Typeface.SANS_SERIF, Typeface.STYLE_ITALIC)
 

Kanne

Member
Licensed User
the callback function is called by the table-class when a row is going to be repainted (called only if such a sub exists).
It is located in the module where you are using the table.
The name of the the sub is a the name of your table extend by
The parameters are allways the row which the table is going to paint and the labels themself as an array.
The sub is called before output, so here you may do anything you want with the labels but you should not change the tableformat itself
(e.g. changing column width could result in an endless loop because changing the width would call a repaint of the table !)
Callback function:
Sub Table1_ShowRow(Row As Int, lbls() As Label)
    ' your code here
End Sub
 

Kanne

Member
Licensed User
it is NOT the table function "myTable.ShowRow(...)" but the callback sub "myTable_ShowRow(...)" !
 

AnandGupta

Well-Known Member
Licensed User
Hi @Sergey_New

I think you have not written 'sub' of events earlier. Maybe you have only tried downloaded complete examples.

I suggest to read klaus booklet where he has explained everything.

Regards,

Anand
 

klaus

Expert
Licensed User
Again. You must add a Table.ShowRow event routine in the module where the Table is used.

Something like this:
B4X:
Private Sub Table1_ShowRow(Row As Int, lbls() As Label)
    If Row = 8 Then
        For i = 0 To lbls.Length - 1
            lbls(i).Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD_ITALIC)
        Next
    End If
End Sub
To easily generate an event routine you should have a look at page 64 in the B4X IDE booklet.
 
Last edited:

Sergey_New

Active Member
Licensed User
AnandGupta, Klaus
I can generate an event routine.
I don't understand where to get the lbls () parameter from.
Please write how to call the execution of Table1_ShowRow.
 

klaus

Expert
Licensed User
You already have it in your test program.
Every time a row is shown in the Table class this event is called.
In the event routine in your example the TypeFace of row 3 is changed.
You need to enter the code for each row where you want to change something.

Or explain exactly what you want to do.
 

klaus

Expert
Licensed User
When I looked at your project I was not aware that you are using version 1.43 a very very old version.
I updated with version 3.26.
In this version the Table is added in the Deisgner.

1620140783475.png
 

Attachments

Top