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,214
  • 1589638550715.png
    1589638550715.png
    31.8 KB · Views: 1,640
  • TestFastScroll.zip
    50.6 KB · Views: 1,486
  • Table.bas
    152.2 KB · Views: 221
  • TableV3_35.zip
    110 KB · Views: 306
Last edited:

Mashiane

Expert
Licensed User
Longtime User
LoadTableFromDataBase & LoadTableFromList

Wow, I must say I found this to be very useful. I wanted to use this with a database and just query the database to generate the tables.
I am able to export the resulting query details to a list and also load the list to the table class with these two methods. However I have a small issue. The table does display the number of rows at the bottom but is however shows a blank table with no details. I then tried to save the list to a csv.csv file and checked this and found that everything is fine however the LoadTableFromCSV also displays a blank table though the number of rows display correctly at the end of the table view class.

Here is the code...

' load the table from a database directly
Public Sub LoadTableFromDatabase(SQL As SQL, Query As String, StringArgs() As String, Limit As Int)
Dim cur As Cursor
Dim colName As String
Dim colValue As String
If StringArgs <> Null Then
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
End If
Log("LoadTableFromDatabase: " & Query)
If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
' all records will be saved to a list including the header
Dim nL As List
nL.Initialize
Dim sb As StringBuilder
' build the header
sb.Initialize
For i = 0 To cur.ColumnCount - 1
colName = cur.GetColumnName(i)
sb.Append(colName).Append(",")
Next
colName = sb.ToString
If colName.EndsWith(",") Then colName = colName.SubString2(0, colName.Length-1)
nL.Add(sb)
' build the records from rows
For row = 0 To cur.RowCount - 1
sb.Initialize
cur.Position = row
For i = 0 To cur.ColumnCount - 1
colValue = cur.GetString2(i)
If colValue = Null Then colValue = ""
sb.Append(colValue).Append(",")
Next
colName = sb.ToString
If colName.EndsWith(",") Then colName = colName.SubString2(0, colName.Length-1)
nL.Add(sb)
Next
cur.Close
' save list to file (ERROR Check, comment the next two lines out on error fix and uncomment LoadTableFromList)
File.WriteList(File.DirRootExternal, "csv.csv", nL) ' the file creates property
LoadTableFromCSV(File.DirRootExternal, "csv.csv", True) ' this displays the number of rows but a blank table
'LoadTableFromList(nL, True) ' this displays the number of rows but a blank table
End Sub

' load table contents to table from a list
Public Sub LoadTableFromList(nList As List, HeadersExist As Boolean)
ClearAll
' the list is empty
If nList.Size-1 < 0 Then Return
Dim h() As String
If HeadersExist Then
Dim headers() As String
' read the first line of the list, it has headers separated by a comma
Dim strH As String = nList.Get(0)
headers = Regex.Split(",", strH)
Dim h(headers.length) As String
For i = 0 To headers.length - 1
h(i) = headers(i)
Next
Else
Dim firstRow() As String
Dim fRow As String
fRow = nList.get(0)
firstRow = Regex.Split(",", fRow)
Dim h(firstRow.Length) As String
For i = 0 To firstRow.Length - 1
h(i) = "Col" & (i + 1)
Next
End If
innerClearAll(h.Length)
ColumnWidth = SV.Width / NumberOfColumns
SetHeader(h)
For i = 0 To nList.Size - 1
Dim row() As String
Dim tRow As String = nlist.Get(i)
row = Regex.Split(",", tRow)
AddRow(row)
Next
End Sub
 

klaus

Expert
Licensed User
Longtime User
Here you have a routine to fill a table with a SQLite query:
B4X:
'load data from a SQLite database
'SQLite = SQL object
'Query = SQLite query
'AutomaticWidths  True > set the column widths automaticaly
Public Sub LoadSQLiteDB(SQLite As SQL, Query As String, AutomaticWidths As Boolean)
    Dim Curs As Cursor
    Curs = SQLite.ExecQuery(Query)

    NumberOfColumns = Curs.ColumnCount
    innerClearAll(NumberOfColumns)

    Dim Headers(NumberOfColumns) As String
    Dim Widths(NumberOfColumns) As Int
    Dim col, row, n As Int
    Dim str As String
    For col = 0 To NumberOfColumns - 1
        Headers(col) = Curs.GetColumnName(col)
        If AutomaticWidths = False Then
            Widths(col) = 130dip
        Else
            n = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize)
            For row = 0 To Curs.RowCount - 1
                Curs.Position = row
                str = Curs.GetString2(col)
                If str <> Null Then
                    n = Max(n, cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize))
                End If
            Next
            Widths(col) = n + 8dip
        End If
    Next
    SetHeader(Headers)
    SetColumnsWidths(Widths)

    For row = 0 To Curs.RowCount - 1
        Dim r(NumberOfColumns), str As String
        For col = 0 To NumberOfColumns - 1
            Curs.Position = row
            str = Curs.GetString2(col)
            If str <> Null Then
                r(col) = str
            Else
                r(col) = ""
            End If
        Next
        AddRow(r)
    Next

    Curs.Close
End Sub
Attached an example with the new Table class.

Best regards.

EDIT:
Removed the zip file, the latest version is in the first post.
 
Last edited:

Espinosa4

Active Member
Licensed User
Longtime User
Hi,
Can I change the font color after addtoactivity?

B4X:
        DateTime.TimeFormat = "HH:mm"
        If CurServiciosReducidos.GetString("TToma") <> Null Then
            Hora = DateTime.TimeParse(CurServiciosReducidos.GetString("TToma"))
            If Hora >= DateTime.TimeParse("11:59") Then
                TblServiciosReducidos.FontColor = Colors.red
            End If
        End If
        TblServiciosReducidos.AddRow(Array As String(Ser,Tom,Dej,Jor,Lin,Noc,Obs,Cor))

Thank you very very much indeed for all!
 

Espinosa4

Active Member
Licensed User
Longtime User
Hi klaus,

It doesn't work for my code.
Why?
The if conditions works perfectly

B4X:
    TblServiciosReducidos.ClearAll
    For i = 0 To CurServiciosReducidos.RowCount - 1
        DateTime.TimeFormat = "HH:mm"
        If CurServiciosReducidos.GetString("TToma") <> Null Then
            Hora = DateTime.TimeParse(CurServiciosReducidos.GetString("TToma"))
            If Hora > DateTime.TimeParse("11:59") Then
                TblServiciosReducidos.TextColor = Colors.red
            Else
                TblServiciosReducidos.TextColor = Colors.blue
            End If
        End If
        TblServiciosReducidos.AddRow(Array As String(Ser,Tom,Dej,Jor,Lin,Noc,Obs,Cor))
    Next

Regards
 

klaus

Expert
Licensed User
Longtime User
I misunderstood your request the first time.
What I added is changing the text color for all entries.
But you ask for changing the text of different lines, unfortunately this is not easily possible because it needs to memorise the text color for each line.

Best regards.
 

Espinosa4

Active Member
Licensed User
Longtime User
I am very sorry, my english is very poor. Sorry.
Ok, I undertand.
Thank you very much indeed for your work!

Best regards
 

AubreyPCR

Member
Licensed User
Longtime User
As a RAD tool, your table class seemed ideal so I gave it a go, very nice, thank you.

I am not using any local DB but rather getting my data in XML format via web services. I needed a generic way of loading data into your table from an internal structure (ie data I had in memory) so I rolled my own and thought I'd share in case it might be useful to someone else.
I store my data in a list of array objects to simulate a simple table structure. I added a sub to your class to load data from such a structure based on your code.

For anyone who is interested, here is the extra sub you can add to your table class and some sample code to show its usage.

This is how I use it :-

B4X:
    Dim ColumnHeaders() As String
    Dim ProductionData as List
  
    ColumnHeaders = Array As String ("ID", "Name", "Description", "StartTime", "EndTime", "Reporter")

    ProductionData.Initialize
    LoadDataToList(ProductionData)

    tblData.LoadListData(ColumnHeaders, ProductionData)

The sub LoadDataToList is used to populate the LIST object with data from your chosen data source. In case it is not obvious here is the code used to add each record (an array object) to the table (list object).

B4X:
       ' inside your data load loop
        Dim r(6) As String
        r(0) = ProdRecordTemp.ID
        r(1) = ProdRecordTemp.Name
        r(2) = ProdRecordTemp.Description
        r(3) = ProdRecordTemp.StartTime
        r(4) = ProdRecordTemp.EndTime
        r(5) = ProdRecordTemp.Reporter
        DataList.Add(r)

This is the sub itself.
It takes two arguments, the first a string array of column headers, the second a list object containing the data. It is assumed that the dimensions of the col headers and record array match (ie that there are the same number of fields per record as there are colum headers).
I left in the "auto column width" code but you could easily modify this sub to accept an extra array of column widths, use fixed width, include the column headers and/or widths in the data list or any other combination that works for you.

B4X:
Public Sub LoadListData(ColHeaderText() As String , DataList As List)
    Dim AutomaticWidths As Boolean
    AutomaticWidths = True
    'AutomaticWidths  True > set the column widths automaticaly
  
    NumberOfColumns = ColHeaderText.Length
    innerClearAll(NumberOfColumns)
  
    Dim Headers(NumberOfColumns) As String
    Dim Widths(NumberOfColumns) As Int
    Dim col, row, n As Int
    Dim str As String
  
    For col = 0 To NumberOfColumns - 1
        Headers(col) = ColHeaderText(col)
        If AutomaticWidths = False Then
            Widths(col) = 130dip
        Else
            n = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize)
            For row = 0 To DataList.Size -1
                Dim r(NumberOfColumns) As String
                r = DataList.Get(row)
                str = r(col)
                If str <> Null Then
                    n = Max(n, cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize))
                End If
            Next
            Widths(col) = n + 8dip
        End If
    Next
  
    SetHeader(Headers)
    SetColumnsWidths(Widths)
  
    For row = 0 To DataList.Size - 1
        Dim r(NumberOfColumns) As String
        r = DataList.Get(row)
        For col = 0 To NumberOfColumns - 1
            If r(col) = Null Then
                r(col) = ""
            End If
        Next
        AddRow(r)
    Next
  
End Sub

Regards
 

Espinosa4

Active Member
Licensed User
Longtime User
Hello,

I've problems after delete a record and the table class refresh.

After delete a record using sql I recharge the table class doing before table.clearall but the deleted record is still there. Can you help me please?

Thank you

Cheers
Carlos
 

Espinosa4

Active Member
Licensed User
Longtime User
Could you post your project ?
It would be much easier to help you, otherwise we need to guess what you have done and how.

Best regards.

Good evening klaus,
Thanks for your fast reply.

Of course, here the code:

B4X:
Sub BtnBorrar_Click
    Dim Result As Int
    If CurTipos.RowCount = 0 Then
        Return
    End If
    Result = Msgbox2("¿Borrar el tipo " & EdtDescripcion.Text &  "?","Confirmar","Si","No","",ImgIcono)
    If Result = DialogResponse.POSITIVE Then
        SQLTipos.ExecNonQuery("DELETE FROM Tipos WHERE NumTipo = " & NumReg)
        DBLoad
    Else
        Return
    End If
End Sub

Sub DBLoad
    Dim Descrip,HorasTra,NTipo As String
    ProgressDialogShow("Un momento por favor")
    TblTipos.Initialize(Me, "TblTipos",3,0,False)
    TblTipos.CellAlignment = Gravity.LEFT
    TblTipos.TextSize = TamanyoTexto
    TblTipos.TextColor = Colors.blue
    If Activity.Width < Activity.Height Then
        TblTipos.AddToActivity(Activity, 0,20dip, 100%x, 40%y)
    Else
        TblTipos.AddToActivity(Activity, 0, 55dip, 100%x, 82%y)
    End If
    TblTipos.HeaderColor = Colors.DarkGray
    TblTipos.HeaderTextColor = Colors.White
    TblTipos.SetHeader(Array As String("Núm","Descripción", "H. Trabajadas"))
    TblTipos.SetColumnsWidths(Array As Int(15%x,55%x,30%x))
    TblTipos.ClearAll
    For i = 0 To CurTipos.RowCount - 1
        CurTipos.Position = i
        If CurTipos.GetString("NumTipo")<> Null Then
            NTipo = CurTipos.GetString("NumTipo")
        Else
            NTipo = ""
        End If
        If CurTipos.GetString("Descripcion")<> Null Then
            Descrip = CurTipos.GetString("Descripcion")
        Else
            Descrip = ""
        End If
        If CurTipos.GetString("HorasTrabajadas")<> Null Then
            HorasTra = CurTipos.GetString("HorasTrabajadas")
        Else
            HorasTra = ""
        End If
        NumReg = CurTipos.GetString("NumTipo")
        EdtDescripcion.Text = Descrip
        EdtHoras.Text = HorasTra
        TblTipos.AddRow(Array As String(NTipo,Descrip,HorasTra))
    Next
    ProgressDialogHide
End Sub

I have also problems with JumpToRow because after the dbload code I can't go directly to a specific record I need write the code into a button event or something like that.

Best Regards
Espinosa
 
Last edited:

klaus

Expert
Licensed User
Longtime User
If you know the row number you should use
B4X:
TblTypos.RemoveRow(Row)
Or in your routine add this code before Initialize.
B4X:
If TblTipos.IsInitialized Then
    TblTipos.RemoveView
End If
TblTipos.Initialize(Me, "TblTipos",3,0,False)

Attached the latest version 1.24
Added RemoveView to remove the whole table.
Added SetCellAlignments(Alignments() As String which allows to set a different alignment for each column.

Best regards.

EDIT:
Removed the zip file, the latest version is in the first post.
 
Last edited:

Espinosa4

Active Member
Licensed User
Longtime User
All works fine, thank you very very much!!!


Thank for all your great work!

Best Regards!
 

Mike Olmsted

Member
Licensed User
Longtime User
I would like to upgrade my app to the newest table but on certain data sets I cannot select the last record in the list.
On my Galaxy S3 it only does it in landscape....on my new Nexus 7 it is almost okay in landscape, portrait almost impossible.
 

Attachments

  • tablever24x.zip
    76.5 KB · Views: 1,035

Mike Olmsted

Member
Licensed User
Longtime User
Thanks for the prompt reply. I find the product amazing.

The problem only occurs when the table exceeds one page. Try to select Wages on page 2 of the table.
If I make the table fit on one page, no problem. This has been happening since ver 1.20. My version 1.13
is fine.
 

Attachments

  • Screenshot_2013-09-23-07-52-45.png
    Screenshot_2013-09-23-07-52-45.png
    190.5 KB · Views: 2,037
Top