B4A Library [Class] Flexible Table

ilan

Expert
Licensed User
Longtime User
thanx klaus

i have allready checked the 2 examples buts i dont understand it
i have never worked with SQL
also if i am programing via VB i save data tu txt file and read from them back

i think i will stary with the tableview it so easy to use

there are some actions that i couldnot figure out how to do them with SQL

those actions i use with the the tableview for my:

B4X:
'adding tableview to activity
 
    Table1.Initialize(Me, "Table1", 21 ,Gravity.CENTER,True)
    Table1.AddToActivity(Activity, 200%x, 0dip, 100%x, 50%y) 
    Table1.clearall
    Table1.SetHeader(Array As String("Col1", "Col2", "Col3", "Col4","Col5","Col6","Col7","Col8","Col9","Col10","Col11","Col12","Col13","Col14","Col15","Col16","Col17","Col18","Col19","Col20","Col21"))

    'loading the tableview
    Table1.LoadTableFromCSV(File.DirInternal,  userid &  "allshifts.csv",True)

 
    'add row to tableview
    Table1.AddRow(Array As String(selecteddate,lb1.Text, lb2.Text,lb3.Text,lb4.Text,lb5.Text,lb6.Text,lb7.Text,lb8.Text,lb9.Text,lb10.Text,lb11.Text,lb12.Text,lb13.Text,lb14.Text,lb16date,lbl.Text,bint,"","0",""))

    'save tableview
    Table1.SaveTableToCSV(File.DirInternal, userid &  "allshifts.csv")
 
     
    'sorting tableview by column
    Table1.sortTable(15,True)
 
    'change value in a cell (col as int, row as int, value as string)
    Table1.SetValue(18, 0, "abc")
 

    'get value from tableview (col as int, row as it)
    nvlb2.Text = Table1.GetValue(2,0)
    '(also with contains option)
    Table1.GetValue(5,i).Contains("לילה")'hebrew letters, no problem with tableview
 
 
    'get table size (size as int)
    size = Table1.Size
 
 
    'search for a value in tableview
    Dim search As String = "abc"
 
    For i = 0 To table1.size - 1
        If search = Table1.GetValue(2,i) Then 'do something
    Next


    'clear complete tableview
    Table1.clearall
 
 
    'remove single row (row as int)
    Table1.RemoveRow(1)


have no idea how to do that with SQLlite
 

klaus

Expert
Licensed User
Longtime User
i have allready checked the 2 examples buts i dont understand it
What do you not understand.
All the functions you use can be done with SQLite and/or with DBUtils.
But you need to learn the SQLite functions and/or DBUtils.
 

ilan

Expert
Licensed User
Longtime User
thank you klaus

derez helped me to understand how to convert tableview to sql
and with his help its easy to understand the basic of sql

B4X:
'After the DB Is created once, no need To Do this
    Table1.SetHeader(Array As String("Col1", "Col2", "Col3", "Col4","Col5","Col6","Col7","Col8","Col9","Col10","Col11","Col12","Col13","Col14","Col15","Col16","Col17","Col18","Col19","Col20","Col21"))

    'loading the tableview
    Table1.LoadTableFromCSV(File.DirInternal,  userid &  "allshifts.csv",True)
'instead:
SQL.Initialize(File.DirInternal,  userid &  "allshifts.db",True)

    'add row to tableview
    Table1.AddRow(Array As String(selecteddate,lb1.Text, lb2.Text,lb3.Text,lb4.Text,lb5.Text,lb6.Text,lb7.Text,lb8.Text,lb9.Text,lb10.Text,lb11.Text,lb12.Text,lb13.Text,lb14.Text,lb16date,lbl.Text,bint,"","0",""))

    'instead:
    SQL.ExecNonQuery2("INSERT INTO Table1 VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) " , (Array As String(selecteddate,lb1.Text, lb2.Text,lb3.Text,lb4.Text,lb5.Text,lb6.Text,lb7.Text,lb8.Text,lb9.Text,lb10.Text,lb11.Text,lb12.Text,lb13.Text,lb14.Text,lb16date,lbl.Text,bint,"","0",""))
 

    'save tableview
    Table1.SaveTableToCSV(File.DirInternal, userid &  "allshifts.csv")
  ' no need To Do
   
    'sorting tableview by column
    Table1.sortTable(15,True)
'    instead:
    SQL.ExecQuery2("SELECT col15 FROM TABLE1 ORDER BY Col15 DESC") ' or ASC
    'change value in a cell (col as int, row as int, value as string)
    Table1.SetValue(18, 0, "abc")
 
    SQL.ExecNonQuery2("UPDATE TABLE1 SET  Col18 =? WHERE Col1=? " , Array As String("abc" , 0 ))

    'get value from tableview (col as int, row as it)
    nvlb2.Text = Table1.GetValue(2,0)
    cur = SQL.ExecQuery2("SELECT col<x> FROM TABLE1 WHERE Col1 = ? ", Array As String(2))
    cur.position = 0
    nvlb2.text = cur.getstring("col1")
 
    '(also with contains option)
    Table1.GetValue(5,i).Contains("לילה")'hebrew letters, no problem with tableview
  cur = SQL.ExecQuery2("SELECT col15 FROM TABLE1 WHERE Col1 = ? ", Array As String("*לילה*"))
  cur.position = 0
    nvlb2.text = cur.getstring("col15")
    'get table size (size as int)
    size = Table1.Size
 
    cur = SQL.ExecQuery("SELECT col1 FROM TABLE1 ")
    size = cur.RowCount
    'search for a value in tableview
    Dim search As String = "abc"
    For i = 0 To table1.size - 1
        If search = Table1.GetValue(2,i) Then 'do something
    Next
 
    cur = SQL.ExecQuery2("SELECT col1 FROM TABLE1 WHERE Col2 = ? ", Array As String("abc"))
    For i = 0 To cur.rowcount -1
        'do someting
    Next


    'clear complete tableview
    Table1.clearall
  'no need
    'remove single row (row as int)
    Table1.RemoveRow(1)
 
    SQL.ExecNonQuery2("DELETE FROM TABLE1 WHERE col1 = ?",Array As String(12))
 

Espinosa4

Active Member
Licensed User
Longtime User
Good night!
I have doubt , is possible to select a row without touching a cell? For example when we do cell long click usually I call the cell click event before. Because in many times I need that cell long click was cell click and after the two events select (with visible colours) the new row selected.

Cheers
 

Espinosa4

Active Member
Licensed User
Longtime User
Hi Klaus,
Firstly I am very sorry to bother you!
I have a new doubt similar to the other question. Is possible when you call to the process JumpToRow the row be selected as well?

Thanks you in Advance.
 

klaus

Expert
Licensed User
Longtime User
You could modify the JumpToRow like this:
B4X:
'Makes the given row visible.
Public Sub JumpToRow(Row As Int, RowSelect As Boolean)
    SV.VerticalScrollPosition = Row * cRowHeight
    DoEvents
    SV.VerticalScrollPosition = Row * cRowHeight
    DoEvents
   
    If RowSelect= True Then
        Dim rc As RowCol
        rc.Row = Row
        rc.Col = 0
        SelectRow(rc)
    End If
End Sub
 

Kerbeross

Member
Licensed User
Longtime User
Thanks Klaus!
It is possible Highlight the row after a long click on her?
The rows and cells come Highlighting only on a Cellclick?
 

klaus

Expert
Licensed User
Longtime User
In the first post you find version 1.30.

Added Public Sub JumpToRowAndSelect(Row As Int, Col As Int) routine
Added Left, Top, Widht, Height and Visible properties.
Added HeaderNames List, you can get any header name with Table1.HeaderNames.Get(col)
Amended line width problem for devices with 0.75 density
 

tufanv

Expert
Licensed User
Longtime User
Hello,

How can i change the sorting of the table automaticly. ? For example i have 7 rows i want to change the sorting of these 7 rows according to the header named ( level) . I want this to happen without user have to click on level header just after created the table and added 7 rows.
 

mcmanu

Active Member
Licensed User
Longtime User


Thank you klaus and sorry i didn´t see that
I will give it a try today
 

mrodriguez

Member
Licensed User
Longtime User
Hello, is there a hideCol() bug?
I use this function but the panel comes without horizontal line color. If i move the panel the new cells get it horizontal line colors.
Also happens if I change the Column Width.

Please just use the demo with this modification:

Sub FillTable
Dim Query As String

Table1.ClearAll

Table1.LineWidth = 3dip
Table1.TextSize = 20

Dim tf() As Typeface
tf = Array As Typeface(Typeface.DEFAULT, Typeface.DEFAULT_BOLD, Typeface.DEFAULT, Typeface.DEFAULT_BOLD, Typeface.DEFAULT)
Table1.SetTypeFaces(tf)

Query = "SELECT * FROM " & DBTableName
Table1.LoadSQLiteDB(SQL1, Query, True)
Table1.hideCol(0) <---------------- PUT THIS
 

Attachments

  • Default_panel.png
    186 KB · Views: 248
  • Panel_moved.png
    191.8 KB · Views: 234
Cookies are required to use this site. You must accept them to continue using the site. Learn more…