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

An improved version of this class is available here: http://www.basic4ppc.com/forum/addi...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.basic4ppc.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: 6,622
Last edited:

solfinker

Member
Licensed User
I have made some search, and I have not find any tutorial about StringUtils.LoadCSV, although I suppose I have to use a List, something similar to the following which is not working:
B4X:
Dim Table1 As List
Dim su As StringUtils
Dim rc As RowCol
Table1 = su.LoadCSV(File.DirRootExternal, "cs/last.txt", ",")
rc.Initialize
rc.Row = 0 : rc.Col = 1
Log("(0,1) " & Table1.Get(rc))
rc.Row = 0 : rc.Col = 2
Log("(0,2) " & Table1.Get(rc))

Any help about finding a tutorial would be apreciated.
Thank you very much for your patience.
 

solfinker

Member
Licensed User
Thank you.
I suppose I'll keep up with the table class.
 

jeffnooch

Member
Licensed User
I created a table and it works great...
i'm also adding some labels, populating the text and formatting like this:


B4X:
        btnClose.Initialize("btnClose")
        lblP1.Initialize("lblP1")
        pnlScores.AddView(btnClose,45%x,90%y,10%x,9%y)
        pnlScores.AddView(lblP1,0,0,45%x,7%y)
       
        lblP1.Text=p1 & " " & p1AvgLbl : lblP1.TextSize=27 : lblP1.Typeface = Typeface.DEFAULT_BOLD :             lblP1.TextColor=txtP1.TextColor

everything looks great the first time i open up the panel
but p1AvgLbl changes and if i open it a 2nd time it looks like the text in the field is overlaying the text that was there the first time it opened...

any thoughts?

thanks
 

klaus

Expert
Licensed User
This is not related to the TableView.
Unfortunately you don't give enough information.

I suppose that you call the code you show several times.
This means that every time you call this code you add a new Label.
As Labes are, by default, transparent you'll see also the texts of all underlaying Labels.
You should add the Label only once and the change only the Text property.

There exist a newer version of the Table Class.
 
Last edited:

jeffnooch

Member
Licensed User
Klaus,
thanks for the reply

yeah the panel was created to show my tables...then i add the labels (essentially as a header for each table shown)...
and yes i have a menu item that can be opened many times which brings up the panel/table/labels
so i guess my next question would be how can i handle it so i only add the label once?
is there a way to check for the existence of the label or another way to handle?

any thoughts would be great...

PS...thanks i'll check out the newer table class when i get a chance...
 

ValDog

Active Member
Licensed User
I am probably having a senior moment, but - how could I use the SaveTableToCSV function to save a table (w/o headers) to a string - instead of a file?
 

ValDog

Active Member
Licensed User
Why do you want to transform the table into a string?
I am storing the table data in a SQLite field, using comma delimited sets (rows) of data. I've been able to write a function to do this - thanks for the response.
 

ValDog

Active Member
Licensed User
Klaus, I've already solved my problem. I was only trying to get the table data into a text field in a way that it could be later read and parsed for use in another module.

Thanks!
 

slavko

Member
Licensed User
Hi,

with great help of examples i did an application for inventory counting. To make more obvious, what cell we need to update, i want to use sentence Table1.SelectedCellColor = Colors.Yellow. My problem is, that no matter, where i put it in code, there is no effect.

Do i need to enable something else to make this work or where this part of coud should be located?

Thx, Slavko
 

klaus

Expert
Licensed User
What version of the class are you using ?
The latest version is 1.43 HERE.
You should put Table1.SelectedCellColor = Colors.Yellow after Table1.Initialize and before filling the Table.
I just tested it in the demo program and it works.
 

slavko

Member
Licensed User
First i replaced 1.37 version with latest one 1.43.

line
Table1.SelectedCellColor = Colors.Yellow is between:
Table.Initialize
and part, where i fill data in:
Table1.LoadTableFromCSV2(File.DirRootExternal & "/Download/", "zaloge.csv", True, ";",True)

in that part i have also other definitions for table eg:
Table1.HeaderTextColor = Colors.Yellow
Table1.TextColor = Colors.Blue
Table1.TableColor = Colors.black

and they are visible -they are working

Should i add a code?
 

klaus

Expert
Licensed User
Without seeing your code it's almost impossible to give a concrete advice.

In the demo program I have this, which works.
B4X:
    Table1.Initialize(Me, "Table1", 5, Gravity.CENTER_HORIZONTAL, True)
    Table1.CellAlignment = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    Table1.HeaderColor = Colors.Blue
    Table1.HeaderTextColor = Colors.Yellow
    Table1.TextColor = Colors.Blue
    Table1.TableColor = Colors.Red
    Table1.RowHeight = 40dip
'    Table1.RowColor1 = Colors.RGB(244,164,96)
'    Table1.RowColor2 = Colors.RGB(255, 153, 255)
  
    Table1.SelectedCellColor = Colors.Yellow
'    Table1.SelectedRowColor = Colors.RGB(255,239,213)
'    Table1.AllowSelection = False
    Table1.AddToActivity(pnlTable, 0, 0, pnlTable.Width, pnlTable.Height)  
  
'    Table1.MultiSelect = True
    Table1.MultiSelect = False
    Table1.SortColumn = False
    Table1.SingleLine = False  
  
'    FillTableFix
'    FillTableSQLite
    FillTableCSV
 

slavko

Member
Licensed User
I added code. Did try to move Table1.SelectedCellColor around , but no luck.

What i did wrong?
Also, why
Table1.UseColumnColors = True
is causing dump if set to True?
 

Attachments

  • Union_tablica.zip
    16.6 KB · Views: 84

slavko

Member
Licensed User
With moving around i found a proper place for definition of colours.

Now, i am having issue with
Table1.SetColumnsWidths(Array As Int(100dip,...,100dip))

code is positioned in the middle of Table1 definintions:
pnlTable.Initialize("")

Activity.AddView(pnlTable, 20dip, 20dip, 100%x - 40dip, 100%y - 200dip)

Table1.Initialize(Me, "Table1", 18, Gravity.CENTER_HORIZONTAL, True)

Table1.AddToActivity(pnlTable, 0, 0, pnlTable.Width, pnlTable.Height)

Table1.SetColumnsWidths(Array As Int(100dip,300dip,200dip,100dip,70dip,5dip,100dip,100dip,100dip,100dip,100dip,100dip,100dip,100dip,100dip,100dip,100dip))

Table1.LineWidth = 10dip
Table1.TextSize = 30
'Table1.UseColumnColors = True
Table1.CellAlignment = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)


During run i am receiveing error:
table_setcolumnswidths (B4A line: 275)
v.Width = w
java.lang.RuntimeException: Object should first be initialized (View).
Did you forget to call Activity.LoadLayout?

What is wrong now?
 

slavko

Member
Licensed User
java.lang.RuntimeException: Object should first be initialized (View).
Did you forget to call Activity.LoadLayout?

A bit misleading message for me. So after fill table with values, SetColumnsWidths works.
 
Top