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

msawada

Member
Licensed User
Longtime User
Having major issue (maybe bug) with TableView modified by Klaus

Thanks for the explanation Klaus.
 

stu14t

Active Member
Licensed User
Longtime User
I'm trying to use the delete row kindly provided by merlot2309

B4X:
Public Sub DeleteRow

    Dim Row As Int

    Row = SelectedRow
    Data.RemoveAt(Row)

    Dim lastRow As Int
    lastRow = Data.Size - 1
    For i = lastRow To 0 Step -1
        If lastRow < (SV.VerticalScrollPosition + SV.Height) / RowHeight + 1 Then
            ShowRow(lastRow)        
        End If
        SelectRow(lastRow)
        SV.Panel.Height = Data.Size * RowHeight
        lastRow = lastRow -1
    Next

    SV.Panel.Height = Data.Size * RowHeight
    
End Sub

I have two problems:

1. the ScrollView SV doesn't have the object variable verticalscrollposition in the TableView class.

2. SelectRow always returns -1 so is out of bounds.

I may be missing something or the TableView class has been updated not sure?

Any help would be great
 
Last edited:

hanyelmehy

Active Member
Licensed User
Longtime User
About Table1.ClearAll

Hi,
Table1.ClearAll not work correctly
when i try to :
-load table with data
-clear table
-load new data with different header

if new data(no of rows) less than old data (no of rows) ,i still see old data rows

i use Table class Version 1.11

any help ,thank you
 

hanyelmehy

Active Member
Licensed User
Longtime User
Code
Sub DoReport1
Dim MySql1
Table1.Initialize(Me, "Table1", 4)
Table1.AddToActivity(Activity, 0,Panel1.Height, 100%x, 100%y-Panel1.Height)
Table1.SetHeader(Array As String("4", "3", "2", "1"))

Table1.SetColumnsWidths(Array As Int(100%x*.20, 100%x*.5, 100%x*.15, 100%x*.15))
Table1.FontSize=14 '14 is default
Table1.RowHeight=50dip '30dip is default

Table1.ClearAll
Dim Cursor2 As Cursor
MySql1="SELECT ProductId,ProductName,Pack1qty,Pack2qty From Products WHERE (Pack1qty=0 AND Pack2qty=0) ORDER BY CategoryId"
Cursor2 = SQL1.ExecQuery(MySql1)
For i = 0 To Cursor2.RowCount - 1
Cursor2.Position =i
Table1.AddRow(Array As String(Cursor2.GetInt("ProductId"),Cursor2.GetString("ProductName"),Cursor2.GetDouble("Pack1qty"),Cursor2.GetDouble("Pack2qty")))
Next
Cursor2.Close
End Sub
'////////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////////
Sub DoReport2
Dim MySql1
Table1.Initialize(Me, "Table1", 4)
Table1.AddToActivity(Activity, 0,Panel1.Height, 100%x, 100%y-Panel1.Height)
Table1.SetHeader(Array As String("4", "3", "2", "1"))
Table1.SetColumnsWidths(Array As Int(100%x*.20, 100%x*.5, 100%x*.15, 100%x*.15))
Table1.FontSize=14 '14 is default
Table1.RowHeight=50dip '30dip is default
Table1.ClearAll
Dim Cursor2 As Cursor
MySql1="SELECT ProductId,ProductName,SUM(Pack1qty),SUM(Pack2qty) FROM Invoice GROUP BY ProductId"
Cursor2 = SQL1.ExecQuery(MySql1)
For i = 0 To Cursor2.RowCount - 1
Cursor2.Position =i
Table1.AddRow(Array As String(Cursor2.GetInt("ProductId"),Cursor2.GetString("ProductName"),Cursor2.GetDouble2(2),Cursor2.GetDouble2(3)))
Next
Cursor2.Close
End Sub


'********************************************
i have two sub (DoReport1 and DoReport2) to make table report
if new data(no of rows from DoReport2) less than old data (no of rows from DoReport1) ,i still see old data rows

Thank you
 

hanyelmehy

Active Member
Licensed User
Longtime User
Hi,
when i remove (Table1.Initialize) and make it once i get this error (even when i put (Table1.ClearAll) first

Act.AddView(SV, Left, Top + RowHeight, Width, Height - RowHeight)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.


Thank you for your time
 

hanyelmehy

Active Member
Licensed User
Longtime User
Hi,
Thank you ,i solve the problem :
i add :

If Table1.IsInitialized Then
Table1.ClearAll
End If

before Initialized table in every sub
 

fdx12345

Active Member
Licensed User
Longtime User
Table - run first time

I have setup a very basic structure for the Table but I get an error on running the application (no errors in compile). The error I get is:

An error has occurred in sub: table_setcolumnswidths(B4A line: 49) v.Width=Widths(i) - 1dip java.lang.RuntimeException: Object should first be initialized (View).

Here is my code related to the Table:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim sms1 As PhoneSms
   Dim Table1 As Table
   Dim Button1 As Button
   Dim Button2 As Button
   Dim Button3 As Button
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim i As Int
   
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("main")
   
   'Create Table using table class
   Table1.Initialize(Me, "Table1", 5)
   Table1.AddToActivity(Activity, 0, 75%y, 100%x, 70%y)
   Table1.SetColumnsWidths(Array As Int(95dip, 70dip, 40dip, 70dip, 70dip))
   Table1.SetHeader(Array As String("Bill Name", "Amount $$", "Due", "Status1", "Status2"))
   Table1.AddRow(Array As String("Mortage", "$1200", "12", "Not Paid", "Not Paid"))

I have not written anymore code conserning the table until I can get pas this problem. My goal is a table 75% of screen in height from the bottom upwards with the top 25% open for other things like buttons.

Possibly the problem is in the size delcaration?
 

gjoisa

Active Member
Licensed User
Longtime User
add table to a panel

Is it possible to add the table to a panel ? In my app I use several panels to display the various functions in a single activity .
 

JTmartins

Active Member
Licensed User
Longtime User
Error in Class Table

Just a quick note, on something I've just found

If we use the table class together with an SQL DB, if a field is empty (null), the class will thrown an error, and will not work.

So make sure all your fields are populated, or check programmatically and change to something as NA, before calling Table.AddRow.
 

BasicBert

Member
Licensed User
Longtime User

Thanks for this fine Class, I'm planning to use it for my new app. I managed to incorporate the class and adapted the main routine to my needs.

At some point in my app I need a value that is in the last row of the table, in column 2. But I don't know which is the last row!

I know I can get a value from the table with code like
B4X:
LaatsteKM = Tabel.GetValue(2, 26)
But the 26 should be a variable pointing to the last row in the table Tabel.

:sign0163:
 

BasicBert

Member
Licensed User
Longtime User
Erel,

Thanks very much.
I modified it a bit because I want the index of the last item in the table.
Therefore I use

B4X:
Public Sub LastEntry As Int
   Return Data.Size-1
End Sub
 

logemag

Member
Licensed User
Longtime User
Unselect ROW ?

Hi Erel, and Happy New Year for all the members !

I want to Unselect a ROW selected by inadvertently, because in my program there are conditions if a row is selected in the rest of my conditions, and we can't unselect, just pass one by one...

I would like just a public sub in the class for unselect this SelectedRow... Thank's !

(excuse my poor english, i'am a poor french !)
 

zeuspower

Member
Licensed User
Longtime User
It works like a charm ! :sign0098:
But..

I have a small problem,because I am using it with sliding panels,and sometimes is a little tricky instead of scrolling horizontaly the table, I slide the panel ...

so I considering using 2 buttons (left-right) to scroll the table,just to be sure the user will be happy...

some small code ,please,if it's not big trouble ? ?
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…