B4A Library [Class] TableView - Supports tables of any size

An improved version of this class is available here: http://www.b4x.com/forum/additional...icial-updates/30649-class-flexible-table.html


The Table class allows you to show tables of any sizes. The views (labels) are reused to avoid creating many views.

With the help of StringUtils the table can be loaded and saved to a CSV file. It shouldn't be difficult to show SQL tables using DBUtils.ExecuteMemoryTable.

SS-2012-07-04_10.38.01.png


Follow the attached example to see how the class is used. To add it to your own project you need to add the class module to your project and add a reference to StringUtils library.

RemoveRow code is available here: http://www.b4x.com/forum/showpost.php?p=146795&postcount=147

V1.10 uploaded. New method: SetColumnsWidths. Allows you to manually set the width of each column
V1.11 uploaded. Fixes a bug with grey stripes appearing.
 

Attachments

  • Table.zip
    14.9 KB · Views: 7,727
Last edited:

buras3

Active Member
Licensed User
Longtime User
i have fixed it sort of
i put back the 1.1 version and copy

Sub Size As Long
Return Data.Size
End Sub

i think the problem was with scrollview2D

tank you
michael
 

ilan

Expert
Licensed User
Longtime User
An improved version of this class is available here: http://www.b4x.com/forum/additional...icial-updates/30649-class-flexible-table.html


The Table class allows you to show tables of any sizes. The views (labels) are reused to avoid creating many views.

With the help of StringUtils the table can be loaded and saved to a CSV file. It shouldn't be difficult to show SQL tables using DBUtils.ExecuteMemoryTable.

SS-2012-07-04_10.38.01.png


Follow the attached example to see how the class is used. To add it to your own project you need to add the class module to your project and add a reference to StringUtils library.

RemoveRow code is available here: http://www.b4x.com/forum/showpost.php?p=146795&postcount=147

V1.10 uploaded. New method: SetColumnsWidths. Allows you to manually set the width of each column
V1.11 uploaded. Fixes a bug with grey stripes appearing.
V1.11_2d with support for horizontal scrolling, modified by klaus, is available here: http://www.b4x.com/forum/111926-post22.html

hi erel

i like to work with the tableview, i am using it to fill with data and then transfer what i need to a clv.
i am not viewing the table on my app, only filling it with data and using it like a LISTVIEW (VB listview item with some subitems)

now my problem is that, when i want to sort the tableview.
i have a col with dates in it like (1/1/2013,...)
and if i sort the tableview it sort it not correctly, like this:

i have 5 dates:
1/1/2013
5/1/2013
11/1/2013
15/1/2013
2/1/2013

after tabel1.quicksort
i get:

1/1/2013
11/1/2013
15/1/2013
2/1/2013
5/1/2013

how can i sort correctly?? please help me !!
thank you very much
 

leonardoffsilva

Member
Licensed User
Longtime User
My code :

B4X:
    TableProduto.Initialize(Me, "TableProduto", 4)
    TableProduto.RowHeight = 70
    TableProduto.AddToActivity(Activity, 0, PanelTop.Height, 100%x, 100%y - PanelTop.Height - PanelBottom.Height)   
    TableProduto.SetHeader(Array As String("Codigo", "Fabricante", "Produto", "Estoque"))
    TableProduto.SetColumnsWidths(Array As Int(80dip, 250dip,  100%x - 410dip, 80dip))


    m_pesquisa = "%" & edtConsulta.Text.ToUpperCase & "%"
    If edtConsulta.Text <> "" Then
        m_sql = "SELECT produtos.id_produto, produtos.descricao, produtos.estoque, fornecedores.fantasia "
        m_sql = m_sql & "FROM produtos "
        m_sql = m_sql & "LEFT JOIN fornecedores ON fornecedores.id_fornecedor = produtos.id_fornecedor "
        m_sql = m_sql & "WHERE produtos.descricao LIKE ? "
        m_sql = m_sql & "ORDER BY produtos.descricao"
        Cursor1 = principal.SQLPrincipal.ExecQuery2(m_sql ,Array As String(m_pesquisa))
    Else
        m_sql = "SELECT produtos.id_produto, produtos.descricao, produtos.estoque, fornecedores.fantasia "
        m_sql = m_sql & "FROM produtos "
        m_sql = m_sql & "LEFT JOIN fornecedores ON fornecedores.id_fornecedor = produtos.id_fornecedor "
        m_sql = m_sql & "ORDER BY produtos.descricao"
        Cursor1 = principal.SQLPrincipal.ExecQuery(m_sql)
    End If
    If Cursor1.RowCount > 0 Then   
        Cursor1.Position = 0
        Try
            principal.produto_id = Cursor1.GetString("id_produto")
'            lbl1.Text = Cursor1.GetString("fantasia")
'            lbl2.Text = "Estoque : " & principal.FormatarNumero(Cursor1.GetString("estoque"),0)
        Catch
            principal.produto_id = 0
'            lbl1.Text = " - - - "
'            lbl2.Text = " - - - "
        End Try   
    End If
    For i=0 To Cursor1.RowCount-1
          Cursor1.Position=i
          TableProduto.AddRow(Array As String(Cursor1.GetString("id_produto"), Cursor1.GetString("fantasia"), Cursor1.GetString("descricao"), Cursor1.GetString("estoque") ))
    Next
TableProduto.JumptoRow(Cursor1.RowCount-1)
 

leonardoffsilva

Member
Licensed User
Longtime User
I changed to :
B4X:
Public Sub JumpToRow(Row As Int)
    SV.VerticalScrollPosition = Row * RowHeight
      DoEvents
    SV.VerticalScrollPosition = Row * RowHeight
      DoEvents   
End Sub

And work partial. The table is invisible.

Need to touch on table to visible again !
 

klaus

Expert
Licensed User
Longtime User
I´m trying to refresh the table to make visible again without need to touch it.
What exactly do you meen ?

Without seeing your code to know what exactly you are doing it's almost impossible to help you.

Best regards.
 

leonardoffsilva

Member
Licensed User
Longtime User
The modification of the code work´s. But the table stay invisible.

Need to thouch with finger to show the table.

I tryed to show after the JumpToRow. but I can´t.

Can anyone help me ?
 

Attachments

  • UsingTable.zip
    1.7 KB · Views: 258
Last edited:

klaus

Expert
Licensed User
Longtime User
Strange, I never encountered this kind of problem.
Testing JumpToRow in a test program with more than 400 items needed the code suggested by Erel but the table is visible.
I don't understand why when touching the screen the table appears.
But unfortunately impossible to test it.

Best regards.
 

fsj

Member
Licensed User
Longtime User
Hi @all

I use the tableview and it works very well

what is the best way to move a row form one position to the other
for example Row 8 (with all the data) should go between row 2 and 3
or row 2 shoul go between 8 and 9
 

ilan

Expert
Licensed User
Longtime User
try this, i didnot checked it but should work

B4X:
Table1.insertRowAt(3,(Array As String(Table1.GetValue(0,8),Table1.GetValue(1,8),Table1.GetValue(2,8))))
Table1.RemoveRow(9)'raw 8 is now 9 because we add between 2 and 3 a copy of raw 8
 

tcgoh

Active Member
Licensed User
Longtime User
Yes. Search the Table class for: "As Label" and change it to "As CheckBox".

Hi,

I've tried the above with a table but it didn't work?

B4X:
For i = 0 To tableal.Size -1
        Dim chk As CheckBox
        chk.Initialize("chk")
        tableal.AddRow(Array As String(chk,"","","","",""))
    Next

anyone can help?

Regards and thanks
 

klaus

Expert
Licensed User
Longtime User
Erel said : Yes. Search the Table class for: "As Label" and change it to "As CheckBox".

You didn't do that.

What exactly do you want to do ?

To make changes in the class you need to analyse and understand the code to know how it works.

Erel's suggestion is true if you replace all Labels by Checkboxes.

You might have a look at the CustomListview class.
 

tcgoh

Active Member
Licensed User
Longtime User
Hi Klaus,

Thanks for the quick reply. I just wanted to add a new col with checkbox into a table which I have already created. Is that possible?
Or do I have to start some New codes and add another CustomListview class to my project?

Thanks
 

klaus

Expert
Licensed User
Longtime User
I just wanted to add a new col with checkbox into a table which I have already created. Is that possible?
This is not possible, in the table class you cannot mix objects.
You should look at CustomListview or make your own CustomScrollview.
For your information, the latest Table class is in this tread.
 
Top