B4A Library [Class] Flexible Table

This thread will be used by Erel, Melamoud and myself to discuss / post new releases of the Table class.

The table class is a flexible UI component that enable scrollable table like UI, with sortable columns, multiselect rows etc

the table is very efficient, maintaining labels only for visible rows

old thread with details : http://www.b4x.com/forum/additional...view-supports-tables-any-size.html#post110901

The class depend on following libraries:
- StringUtils (standard)
- SQL (standard)
- JavaObject (standard)
- B4XCollections (standard)
- ScrollView2D (additional)

List of major features.
1. scrollable table UI
2. sortable columns
3. select a row, cell or multi select rows
4. callback for selection / click a cell / row
5. callback for long click action
6. read / write to CSV file

Current version --> 3.35 Custom View
Current version --> 1.44 Class

Other complementary routines:

Load data with the Remote Database Connector.


EDIT: LucaMs has written a routine to fill a table with a Remote Database Connector query result see post 182.
The routine hasn't been added into the Class for the reasons explained in post 183.
A sample program can be found HERE.

Code:
B4X:
'load data from a RDC Request
'Result = DBResult object got from a RDC request
'AutomaticWidths  True > set the column widths automaticaly
'Written by LucasMs
Public Sub LoadRDCResult(Result As DBResult, AutomaticWidths As Boolean)
    cAutomaticWidths = AutomaticWidths
    NumberOfColumns = Result.Columns.Size
    innerClearAll(NumberOfColumns)

    Dim Headers(NumberOfColumns) As String
    Dim ColumnWidths(NumberOfColumns) As Int
    Dim HeaderWidths(NumberOfColumns) As Int
    Dim DataWidths(NumberOfColumns) As Int
    Dim col, row As Int
    Dim str As String
    For col = 0 To NumberOfColumns - 1
        Headers(col) = Result.Columns.GetKeyAt(col)
        If AutomaticWidths = False Then
            ColumnWidths(col) = 130dip
            HeaderWidths(col) = 130dip
            DataWidths(col) = 130dip
        Else
            HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth
            DataWidths(col) = 0

            Dim FieldValue As Object
            For row = 0 To Result.Rows.Size - 1
                Dim Record() As Object = Result.Rows.Get(row)
                FieldValue = Record(col)
                If GetType(FieldValue) = "java.lang.String" Then
                    DataWidths(col) = Max(DataWidths(col), cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth)
                End If
            Next
            ColumnWidths(col) = Max(HeaderWidths(col), DataWidths(col))
        End If
    Next
    SetHeader(Headers)
    SetColumnsWidths(ColumnWidths)

    For Each Record() As Object In Result.Rows
        Dim R(NumberOfColumns) As String
        Dim FieldV As String
        For col = 0 To NumberOfColumns - 1
            FieldV = Record(col)
            R(col) = FieldV
        Next
        AddRow(R)
    Next
End Sub

This is another routine updated by cimperia in post #392 using a Map for the columns and a List for the rows.
B4X:
'load data from a RDC Request
'A RDC request returns a DBResult object, therefore this method
'could be called as is:
'LoadRDCResult(DBResult.Columns, DBResult.Rows, True)
'AutomaticWidths  True > set the column widths automaticaly
'Written by LucasMs
Public Sub LoadRDCResult(Columns As Map, Rows As List, AutomaticWidths As Boolean)
  cAutomaticWidths = AutomaticWidths
  NumberOfColumns = Columns.Size
  innerClearAll(NumberOfColumns)

  Dim Headers(NumberOfColumns) As String
  Dim ColumnWidths(NumberOfColumns) As Int
  Dim HeaderWidths(NumberOfColumns) As Int
  Dim DataWidths(NumberOfColumns) As Int
  Dim col, row As Int
  Dim str As String
  For col = 0 To NumberOfColumns - 1
    Headers(col) = Columns.GetKeyAt(col)
    If AutomaticWidths = False Then
      ColumnWidths(col) = 130dip
      HeaderWidths(col) = 130dip
      DataWidths(col) = 130dip
    Else
      HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth
      DataWidths(col) = 0

      Dim FieldValue As Object
      For row = 0 To Rows.Size - 1
        Dim Record() As Object = Rows.Get(row)
        FieldValue = Record(col)
       If GetType(FieldValue) = "java.lang.String" Then
         DataWidths(col) = Max(DataWidths(col), cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth)
       End If
      Next
      ColumnWidths(col) = Max(HeaderWidths(col), DataWidths(col))
    End If
  Next
  SetHeader(Headers)
  SetColumnsWidths(ColumnWidths)

  For Each Record() As Object In Rows
    Dim R(NumberOfColumns) As String
    Dim FieldV As String
    For col = 0 To NumberOfColumns - 1
      FieldV = Record(col)
      R(col) = FieldV
    Next
    AddRow(R)
  Next
End Sub


Load data from a MSMariaDB database.

Another routine for loading data from a MSMariaDB database can be found in post#727.
Thanks to @Magma.

Updates:
EDIT: 2024.04.21 Version 3.35
Replaced the original sorting functions by new ones kindly provided by forum member RB Smissaert.
Amended first scroll scrolling back to 0
Amended Header with transparent color

EDIT: 2024.01.13 Version 3.33
Changed possible values for DataType
TEXT and NUMBER become T, R and I
Amended problem with column colors
Amended problems with SetHeaderColors and SetHeaderTextColors

Version 3.32
Amended Header and HeaderFirst problem in SaveCSVFromTable
Moved If (lblStatusline... from AddRow to ShowRow

Version 3.31
Added SingleLine property for the Designer
Added StatusLineHeight as a property
Added FastScrollLabelMaxChars as a property

EDIT: 2021.06.28 Version 3.30
Added a check for none numeric values for numeric sorting.

EDIT: 2021.06.28 Version 3.29
Amended problem with column colors
Version 3.28
Added NumberOfColumns in the code
Added TopRowIndex method
Version 3.27
Amended MultiSelect EDIT: 2020.09.02 Version 3.26
Amended problem with sort with remove accents
Amended problem with SetRowColorN
Added SetCellAlignmentColN method
Added SetHeaderAlignmentColN method

EDIT: 2020.08.05 Version 3.24
Amended problem with JumpToRowAndSelect not being selected.
Amended error when setting RowHeight before the table initialized

EDIT: 2020.06.19 Version 3.22
Amended error in the insertRowAt routine.

EDIT: 2020.05.25 Version 3.21
Amended bug with TextSize in fixed columns

EDIT: 2020.05.16 Version 3.20
Added fast scroll feature
Version 3.19
Improved automatic width calculation and hidden columns
Version 3.18
Added a check in RemoveRowColorN to ensure that Row is not out of bounds
Added ShowRow event
Amended automatic width calculations
Amended hidden column width problem

EDIT: 2020.04.21 Version 3.17
Amended HeaderHight problem with fixed columns

EDIT: 2020.04.21 Version 3.16
Amended two errors.

EDIT: 2020.04.14 Version 3.14
Added the methods below
- LoadSQLiteDB4(SQLite As SQL, Query As String, AutomaticWidths As Boolean)
loads SQLite data with data type checking
- LoadSQLiteDB5(SQLite As SQL, Query As String, Values() As String, AutomaticWidths As Boolean).
loads SQLite data with data type checking , similar to LoadSQLiteDB4 but for parametrized queries.
- GetColumnDataTypes As String(), returns an Array with the data type for each column.
- GetColumnDataType(Column As Int) As String, returns the data type of the fiven column.
Added the InnerTotalWidth property, read only.
Added multiple first fiexed columns
Added line colors

EDIT: 2020.03.10 Version 3.10
Amended bug reported HERE

EDIT: 2020.03.06 Version 3.09
Amended bug reported HERE.

EDIT: 2020.02.29 Version 3.08
Amended SetHeaderTypefaces method problem reprted HERE.
Added HeaderTypeface property.

EDIT: 2020.01.08 Version 3.07
Amended bug ShowStatisLine = False property bug.
Added MultiSelect property to Designer properties.
You need to open and close the Designer when you use the new version the first time to make the MultiSelect property active.

EDIT: 2019.12.28 Version 3.06
Amened some bugs

EDIT: 2019.12.25 Version 3.05
Added FirstColumnFixed property which allows to fix the first column.
Attention: You need to open and close the Designer to make the new property active.

EDIT: 2019.11.15 Version 3.04
- Added SelectedRowTextColor and SlectedCellTextColor properties
- Added ZeroSelections property, True > when a selected row is pressed it will be unselected False > it remains selected.

EDIT: 2019.11.12 Version 3.03
- Changed JumpToRowAndSelect(Row As Int, Col As Int) to JumpToRowAndSelect(Col As Int, Row As Int)
- Changed LoadSQLiteDB2 signature. Replaced the possible values from "T", "I", "R" to "TEXT", "NUMBER" for coherence with SetColumnDataTypes.
- Added internal sorting bitmaps, avoids loading the image files into the Files folder.
- Added two new properties: SortBitmapWidth and SortBitmapColor.
- Added SetCustomSortingBitmaps method, which allows to use custom bitmaps instead of the internal ones.
Attention: You need to open and close the Designer to make the new properties active.
Attention: You need to invert the parameters in JumpToRowAndSelect.

EDIT: 2019.07.04 Version 3.02
Amended error reported in post #887

EDIT: 2019.06.26 Version 3.01
Amended SingleLine property setting in the code

EDIT: 2019.04.05 Version 3.00
Amended SetColumnColors and SetTextColors
Removed Reflection library dependency

EDIT: 2018.04.11 Version 2.29
Version 2.27
set the two variables sortedCol and sortingDir to Public instaed of Private
added RemoveAccent routine for sorting with accented characters
Version 2.28
Added SetHeaderTypeFaces
Added SortRemoveAccents property
Version 2.29
Added SaveTableToCSV2 with a user defined separator character

EDIT: 2018.04.11 Version 2.26
added LoadSQLiteDB3 method using SQLExec2 instead of SQLExec
The query can include question marks which will be replaced with the values in the array.

EDIT: 2018.03.27 Version 2.25
amended minor errors
added UpdateCell method

EDIT: 2017.11.19 Version 2.22
improved JumpToRowAndSelect scrolls horizontally to the selected column
improved setHeaderHeight
added padding for status bar Label

EDIT: 2017.06.27 Version 2.19
Replaced DoEvents by Sleep(0)
Asked HERE

EDIT: 2017.06.27 Version 2.19
Replaced DoEvents by Sleep(0)
Asked HERE

EDIT: 2017.05.16 Version 2.18
Amended error reported HERE.

EDIT: 2017.03.09 Version 2.17
Amended error reported HERE.

EDIT: 2017.03.09 Version 2.15
Amended error reported here, Event signatures
#Event: CellClick(col As Int, row As Int)
#Event: CellLongClick(col As Int, row As Int)

EDIT: 2016.12.05 Version 2.14
Added NumberOfColumns and NumberOfRows as Public variables.
Amended error reported here.

EDIT: 2016.12.05 Version 2.13
Amended error reported here.
Added NumberOfColumns as a property for the Designer.

EDIT: 2016.07.30 Version 2.10
Amended error with TextAlignment and HeaderTextAlignment reported in post #606

EDIT: 2016.03.15 Version 2.00
Added CustomView support.
This version can be compiled into a library.
Changes between the previous versions and version 2.00
For a Table added in the Designer, this is new
No need to initialize nor add it onto a parent view
'For a Table added in the Designer, this is new
'No need to initialize nor add it onto a parent view

For a Table added in the code:
The Initialize routine has been splittend into two routines.
New:
Initialize (CallBack As Object, EventName As String)
InitializeTable (vNumberOfColumns As Int, cellAlignement As Int, showStatusL As Boolean)

'Example:
Table1.Initialize(Me, "Table1")
Table1.InitializeTable(5, Gravity.CENTER_HORIZONTAL, True)


Old:
Initialize(CallBack As Object, EventName As String, vNumberOfColumns As Int, cellAlignement As Int, showStatusL As Boolean)
Example:
Table1.Initialize(Me, "Table1", 5, Gravity.CENTER_HORIZONTAL, True)

EDIT: 2015.04.29 Version 1.43
As the modifications in LoadSQLiteDB don't work in all cases I went back.
LoadSQLiteDB as in version 1.40
Added LoadSQLiteDB2 where the column data types must be given.

EDIT: 2015.04.26 Version 1.42
Changed he LoadSQLiteDB routine, version 1.41 didn't work as expected.
The final solution was suggested by cimperia HERE.

EDIT: 2015.04.16 Version 1.41
Changed the LoadSQLiteDB routine according to the error reported in the SQL issue thread
and the SQLite Cursor GetString versus GetDouble thread.
The problem appears with numbers bigger than 999999.
I left version 1.40 in case of problems.
I tested it with a few databases, but I am not sure if it works in all cases.

EDIT: 2015.03.05
Amended bugs reported in posts #383 and #386
Added SetAutomaticWidths routine

EDIT: 2015.02.19
Amended the problem alignment reported in post # 378

EDIT: 2015.02.13
Amended the problem of rows not shown reported in post # 371

EDIT: 2015.01.09
Added header aligments

EDIT: 2014.08.14
Added HeaderHeight property
Amended RowColor problem reported in post #260

EDIT: 2014.08.10
Added SortColumn property asked in post #266
Added UseColumnColors ColumnColors and HeaderColors propeties

EDIT: 2014.05.10 Added RowHeight as a property

Screenshot:

1589638570453.png
 

Attachments

  • TableV1_44.zip
    44.8 KB · Views: 2,218
  • 1589638550715.png
    1589638550715.png
    31.8 KB · Views: 1,641
  • TestFastScroll.zip
    50.6 KB · Views: 1,487
  • TableV3_35.zip
    110 KB · Views: 308
  • Table.bas
    152.2 KB · Views: 225
Last edited:

Kanne

Member
Licensed User
Longtime User
there seems to be a problem when using hidden cols AND fixed cols at the same time (I did not have this in my project).
In my example hiding is ok, fixing is ok - but when using both at the same time I get garbage of the hidden cols
B4X:
    sQuery.Initialize
    sQuery.append(" Select ID_Spieltag, ID_Spiel, Punkte, Punkte_S1, Punkte_S2, Punkte_S3, Punkte_S4, Punkte_S5 from Spiel")
    Table1.LoadSQLiteDB(SQL1, sQuery.ToString, True)
    Table1.SetAutomaticWidths
    Table1.NumberOfFixedColumns = 2
    Table1.hideCol(0)
    Table1.hideCol(3)
    Table1.hideCol(4)
 

Attachments

  • Screenshot_20200505_234508_temp.jpg
    Screenshot_20200505_234508_temp.jpg
    128.1 KB · Views: 233

klaus

Expert
Licensed User
Longtime User
@Kanne and @artsoft
I had a look at your problems and suggestions.
The problem with the missing borderline is solved for the nest update.
I added the ShowRow routine, but currently the visible rows are not updated at the first run. Does it work for you?
What kind of TTF font are you using?
@artsoft Could you post a project showing your problem with the columns and colors.
It would be much easier for me to find the problems that trying to reproduce it, not knowing exactly how it is done.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
yes, all rows can be colored
I know, but I tested it with:
B4X:
Sub Table2_ShowRow(Row As Int, lbls() As Label)
    Private i As Int
    i = lbls(0).Text
    If i < 20 Then
        lbls(0).Color = Colors.Red
    End If
End Sub
The first rows are not colored.
1588790734165.png

After scrolling:
1588790800575.png
 

Kanne

Member
Licensed User
Longtime User
I made a small project - is running as expected. can you test it please ?
At start fields are red / gray und you can set random colors via menu ...

I also tested if it might only occur when not filling by SQL - so I made a cursor and filled it by adding rows:
coloring works well, but I got some other problems here: how can I change column count by code ?
I always got an error, worked only when setting correct number of cols in designer / initialize of runtime table.
Designer table also had a strange behavior: when setting status line to false, no data was shown !
 

Attachments

  • Screenshot_20200506_220134_temp.jpg
    Screenshot_20200506_220134_temp.jpg
    181.7 KB · Views: 214
  • Screenshot_20200506_220114_temp.jpg
    Screenshot_20200506_220114_temp.jpg
    163.7 KB · Views: 224
  • B4A Test Table.zip
    28.4 KB · Views: 219
Last edited:

klaus

Expert
Licensed User
Longtime User
Your project works.
But my test program didn't modify the first visible rows.
Took me a while to find out what happened.
The problem is the length of the database, during the filling of the table the ShowRow was not executed.
I added a Sleep(0) before calling the external ShowRow routine.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I changed the SQLiteLoader because there was only an automatic column width calculation with the DEFAULT font.
Now LoadSQLiteDB_Font works with my own TTF-font in a correct way.
You should set the TypeFace before calling LoadSQLiteDB, and the automatic width calculation works.
This is the same as for all general properties.

For the problem in post #1018, can you please post a small project showing the problem.
 

artsoft

Active Member
Licensed User
Longtime User
You should set the TypeFace before calling LoadSQLiteDB, and the automatic width calculation works.
This is the same as for all general properties.

For the problem in post #1018, can you please post a small project showing the problem.

See my comment for this below in the next post!

The other problem with the row colors .... I have found a very simple solution: I only work now with selectionColor ... this looks pretty nice and better as with lot of different colors.

The biggest problem I have is this one ...
I will show you this with this simple workflow:

1.


I create a new table object (not via designer, but via code):

B4X:
Private Table2 As Table

2.

I initialize this one by:

B4X:
    Table2.Initialize(Me, "Table2")
    Table2.AddToActivity(Activity, formdescr.left, formdescr.Top + formdescr.Height + 5dip, formdescr.Width, 30%y)

3.

I set some properties (while using my own font) by calling a special method:

B4X:
Table2.clearSelection
    Table2.ClearAll

    Table2.SetHeaderTypeFaces(Array As Typeface(font_bold_g))
    Table2.SetTypeFaces(Array As Typeface(font_normal_g))

    Table2.InitializeTable(4, Gravity.LEFT, False)
    Table2.SetHeader(Array As String("Title", "Bold", "Password", "Max"))
  
    Table2.TextSize = 13

    Table2.RowHeight = (Table2.Height / 7)
    Table2.HeaderHeight = (Table2.Height / 7)

    Table2.ZeroSelection = True
    Table2.ShowStatusLine = False  ' By the way --> I have to do this: The third 'False' parameter of InitializeTable has no effect!


After this, I see logically only the header row.


4.

Then I add a row with a given String array "s":

B4X:
Table2.AddRowAutomaticWidth(s)

The array is:

s(0) = "BlaBla"
s(1) = "YES"
s(2) = "YES"
s(3) = "50"

Followed by this command:

B4X:
Table2.RefreshTable


5.

Now I see the header and the inserted row (see point 4 above).

6.

Then I add a next row with "s" Array:

s(0) = "XxxXxx"
s(1) = "YES"
s(2) = "NO"
s(3) = "25"

in the same way as described in point 4 (above).

Now I see the header row and two rows with "XxxXxx", "YES", "NO" and "25".

======================================================

My question is now ...... what is wrong here?


When I remove this command:

B4X:
Table2.RefreshTable

Then I see the correct table ............. so far so good.

But when I click on any row in the table, the label in this row is updated to the last inserted values.

In my case I see first:

Header...
BlaBla...
XxxXxx...

(... means = Rest of row)

After click on BlaBla, I see :

Header
XxxXxx...
XxxXxx...

Very strange!

I guess that there is missing an important command or something like this.
Or could it be that I am using currently an old version of Table.bas?

Unfort. I may not show you any screenshot - the requester of the app did not allow that.

If you can provide a newer version of the table custom view - that would be very, very nice!

Best regards and many thanks in advance
Artsoft
 
Last edited:

artsoft

Active Member
Licensed User
Longtime User
You should set the TypeFace before calling LoadSQLiteDB, and the automatic width calculation works.
This is the same as for all general properties.

For the problem in post #1018, can you please post a small project showing the problem.

Not really, Klaus.

In your method:
B4X:
Public Sub LoadSQLiteDB(SQLite As SQL, Query As String, AutomaticWidths As Boolean)
You execute a font measurement, yes (in case of AutomaticWidths parameter is set to TRUE) .... but not on given user font ... but on Typeface.DEFAULT font:
B4X:
HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + ExtraWidth
You should use the font given by outside for your measurement.

Regards
Niko
 
Last edited:

Kanne

Member
Licensed User
Longtime User
maybe it' s a bug, but you can easily solve this problem by calling .SetAutomaticWidths after filling.
 

Kanne

Member
Licensed User
Longtime User
according to your strange data:
are you shure, that you make a new DIM before adding 2nd row ?
it sounds for problems due to pointers cauesed of doing no 2nd redim ...
you may download my testproject running without problems filling by calling sql-filling or filling manually by cursor.
It would be much easier to find your problem if you would upload your project ...
 

klaus

Expert
Licensed User
Longtime User
Can you please test the attached Table.bas class version 3.18.
- Added a check in RemoveRowColorN to ensure that Row is not out of bounds
- Added ShowRow event
- Amended automatic width calculations
- Amended hidden column widths

@artsoft
The problem you mention in post #1033 is due, as Kanne already suggested, to the missing Dim statement before each AddRow.
I have still not understood your color problem.
 

Attachments

  • Table.bas
    108.2 KB · Views: 219
Last edited:

Kanne

Member
Licensed User
Longtime User
Hi,
new test looks better, but it seems that a border of hidden cols is still painted / calculated.
In the examples I fixed the first two cols (0/1) and hided col 0 / 4 / 5: as result I get a left offset due to hidden col0 and a bigger line where col 4&5 were hidden.
Linewidth was set to 3dip and the line in the middle seems wider than on the left margin which seems wider than normal borderline - so I think one of the borders of the hidden cols is still added in calculation.
 

Attachments

  • Screenshot_20200509_142533_temp.jpg
    Screenshot_20200509_142533_temp.jpg
    131.1 KB · Views: 213

artsoft

Active Member
Licensed User
Longtime User
Can you please test the attached Table.bas class version 3.18.
- Added a check in RemoveRowColorN to ensure that Row is not out of bounds
- Added ShowRow event
- Amended automatic width calculations
- Amended hidden column widths

@artsoft
The problem you mention in post #1033 is due, as Kanne already suggested, to the missing Dim statement before each AddRow.
I have still not understood your color problem.

Yes, you both are right .......... the problem was the PRIVATE init statement outside of the FOR-loop. Now I switched it to a DIM statement inside of the FOR-loop and this looks good now.

And the problem with the font measurement is also fixed!!! :) Great work!

_____________________________________________________

Ok, let us go to the next problem with the colors:

Unfortunately I may not upload any part of the app - the app requester doesn't allow this to me. So, I can only described in detail and in a good way what happens here:

But I found something strange - BUT helps in my case:

1. I have a simple table named formtypes with some columns (see the select below in code section please).

2. Only for test I put a button on the GUI which makes two things:

a.) Deletion of the complete table content by using this SQL: deletes from formtypes
And then call a Table update method (see below)

b.) Insertion of 100 dummy records within this table in order to have something to show on GUI (in the Table custom view).
And then call a Table update method (see below)

In point b there are also foreground and background data - created randomly. Look here:

B4X:
    Private i As Int
    Private ft As form_type
    ft.Initialize

    For i = 1 To 100
        ft.fg_color = Colors.ARGB(255,Rnd(0,255),Rnd(0,255),Rnd(0,255))
        ft.bg_color = Colors.ARGB(255,Rnd(0,255),Rnd(0,255),Rnd(0,255))
        ft.name = "Form " & Rnd(1000, 2000) & DateTime.Now
        ft.descr = "Test"
        DB.saveFormTypesObj(ft)
    Next


And here the update method for the GUI table:

B4X:
Sub updateFormTypeList()

    Dim i As Int
    Dim font_normal_g As Typeface
    Dim font_bold_g As Typeface
    Dim gothic_font As Typeface

    gothic_font   = Typeface.LoadFromAssets("myfont.ttf")
    font_normal_g = Typeface.CreateNew(gothic_font, Typeface.STYLE_NORMAL)
    font_bold_g   = Typeface.CreateNew(gothic_font, Typeface.STYLE_BOLD )

    ' ------------------------------------------------------------------------------

    Table1.clearSelection
    Table1.ClearAll
    Table1.SetHeaderTypeFaces(Array As Typeface(font_bold_g))
    Table1.SetTypeFaces(Array As Typeface(font_normal_g))
    Table1.TextSize = 13
    Table1.RowHeight = (Table1.Height / 7)
    Table1.NumberOfFixedColumns = 0

    Table1.LoadSQLiteDB (DB.SQL1, "SELECT name, descr, id, fg_color, bg_color FROM formtypes ORDER BY name", True)

    Table1.HeaderHeight = (Table1.Height / 7)
    Table1.SetHeader(Array As String("Name", "Description", "", "", ""))

    Table1.hideCol(2)
    Table1.hideCol(3)
    Table1.hideCol(4)

    ' Set the row colors...
    If Table1.NumberOfRows > 0 Then
        For i = 0 To (Table1.NumberOfRows-1)
            Table1.SetRowColorN(i, Table1.GetValue(4, i))
        Next
    End If

End Sub


Looks very easy ..... but after a click on my button ... the old colors from view before (before the click on the button) appears.

My solution now:

I added a "Sleep(0)" (Formerly: DoEvents) command after Table1.ClearAll command ... and now the view is ok:

B4X:
    Table1.ClearAll
    Sleep(0) ' ------------- ADDED

So, I guess this is probably an update issue or something like this.

By the way:
My Table1 object comes from B4A Designer and it is not added manually.
But I think, this cannot be the reason for this runtime issue.


In a next post, I will also describe another issue ... could be that a command is missing in this case.

Thanks all of you for the big help.

Best regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
In my app I need to know the action (the touch action) on how to scroll the table content!

To the developer of this table custom view:

I added this code at the end of the method DesignerCreateView:

B4X:
    Dim R As Reflector
    R.Target = SV2
    R.SetOnTouchListener("Table_Touch")


And in the Table.bas code I added this Sub correspondent to the code above:

B4X:
Sub Table_Touch(ViewTag As Object, Action As Int, X As Float,Y As Float, Motionevent As Object) As Boolean
    If SubExists(cCallBack, cEventName & "_Touch") Then
        CallSub2(cCallBack, cEventName & "_Touch", Action)
    End If
    Return False
End Sub


Then, within my app, I can simple react to the relevant action.
In my case this the ACTION_UP action:

B4X:
Sub Table1_Touch (Action As Int)

    If (Action == Activity.ACTION_UP) Then
        Tools.protectStart
    End If

End Sub

The scroll change event fires to often an event ..... so this event is not a good solution in my case.

Only an idea...:)

Best regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
Ok, this is the post now which describes another (small) problem.

So, I hope this issue is only on my side here - cause of missing commands or something like this.

Description:

1. I have added manually a Table object in my Activity. This is the Table object with the PRIVATE and DIM statement commands. (See above!)

2. If I add only strings, which are (in sum) smaller than the width of the table object (that means: There is no need to scroll vertically in order to see all table data), then I cannot select a row. It feels that the Table object is disable for any touches, moves or clicks.

3. If I add longer strings, which are (in sum) greater than the width of the Table object (that means: There is a need now to scroll vertically in order to see all table data), then I can work with the table normally: I can select or unselect rows (ZeroSelection is set to TRUE), I can scroll the table ...... absolutely normal.

Therefore my question: Whats wrong here? Do I make a mistake?

This is my update method (while reading a list of data):

B4X:
    Table2.clearSelection
    Table2.ClearAll

    selected_row = -999
    
    Sleep(0)

    Table2.SetHeaderTypeFaces(Array As Typeface(font_bold_g))
    Table2.SetTypeFaces(Array As Typeface(font_normal_g))

    Table2.InitializeTable(4, Gravity.LEFT, False)
    Table2.SetHeader(Array As String("Title", "Bold", "Password", "Max"))

    Table2.TextSize = 13

    Table2.RowHeight = (Table2.Height / 5)
    Table2.HeaderHeight = (Table2.Height / 5)

    Table2.ZeroSelection = True
    Table2.ShowStatusLine = False

    If (mylist.Size > 0) Then
        
        For i = 0 To (mylist.Size -1)
            
            Dim ff As form_field
            Dim s(4) As String

            ff = mylist.Get(i)
            
            s(0) = ff.title
            
            If (ff.bold == 1) Then
                s(1) = "yes"
            Else
                s(1) = "no"
            End If

            If (ff.password == 1) Then
                s(2) = "yes"
            Else
                s(2) = "no"
            End If
            
            s(3) = ff.maxchars
            
            Table2.AddRowAutomaticWidth(s)
        
        Next
        
    Else
        ' no opcode       
    End If

    Table2.RefreshTable


Best regards
ARTsoft
 
Top