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: 7,179
Last edited:

staticmike

Member
Licensed User
Longtime User
Love the table class library and figured most of it out apart from how to change the row colours ?
I would like to change the Cyan colour to one that matches my app and have looked through the code trying to find a clue as to where this cyan colour is coming from.

I thought it might be something like -

table1.RowColor2 = Colors.Magenta

Any help would be appreciated.

Thanks
 

Mahares

Expert
Licensed User
Longtime User
I am pretty sure it is this line in the class module. Change it to a different color other than cyan if you want:
cRowColor2 = 0xFF98F5FF
 
Last edited:

staticmike

Member
Licensed User
Longtime User
Thanks Klaus.
Looks like i'm on version 1.1. I will try again and thanks again for the quick response.
 

deyvitm

Member
Licensed User
Longtime User
someone has some example of a grid column where you can have as a button or a link, when you click go to an event and can run something, I hope I can help
 

deyvitavara

New Member
Licensed User
Longtime User
Excelent erel,
But I can add a button or an image in a column for that row by row you see the image and you can give specific click for a more ideal design theme , thanks
 

tamayo461

Member
Licensed User
Longtime User
Hi,

Added 2 Delete Subs and an Insert Sub to this class.
The Class Module:
B4X:
Public Sub InsertRow(Values() As String)
   If Values.Length <> NumberOfColumns Then
      Log("Wrong number of values.")
      Return
   End If
   Data.InsertAt(0, Values)

   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
  
End Sub

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
Public Sub DeleteRow_Database

   Dim Col, Row As Int
   Row = SelectedRow
   Col = GetValue(11, Row) 'Change the Col value to select the Col that you need for a db

   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

The Activity Module:
B4X:
tbInput.InsertRow(Array As String(the fields.............))
and
B4X:
tbInput.DeleteRow               'Table only
or
tbInput.DeleteRow_Database 'Table and database

Saludos,
Helen.


Hi @Merlot2309 i have a problem when i try to delete the last Row, the app close without error. do you know for what?
 

vbmundo

Well-Known Member
Licensed User
Hi,

I'm using your Class, and have a problem creating a second Table in other Layout..

This is my first Table and works fine

g.Initialize(Me, "g", 2)

And this is my second Table

gc.Initialize(Me ,"gc",4)

Of any reason, the second Initialize don't set the NumberOfColumns value correctly.

When I debug the code the NumberOfColums property by 0 after the Initialize

What's Wrong ?

Regards
 

vbmundo

Well-Known Member
Licensed User
Hard to say without seeing the code. There should be no problem adding multiple tables.

Hi

I see the problem... I turn to LandsCope before create the Table using the Phone class

In Portrail works good, but when you change the orientation before doesn't work.

Obviously this is a bug.

I need to show a long table in Landscope, but this don't work with this Table Class

Regards
 

vbmundo

Well-Known Member
Licensed User
Yes, but Look

I has this line before create the TAB

MyPhone.SetScreenOrientation(0)

And the Table turn the columns in '0'

when I quit this line... all works fine...
 

Lyndon Bermoy

Active Member
Licensed User
Longtime User
Hello good day! I tried so many codes on the table_cellclick but I cannot get the correct code on showing or selecting the rows of the table on the database because it always shows the last field/record of the database.

Here's my code:

B4X:
Sub Table1_CellClick (Col As Int, Row As Int)


   Main.cursor1 = Main.sql1.ExecQuery("SELECT * FROM tblStudent")
For i = 0 To Main.cursor1.RowCount - 1
Main.cursor1.Position = 0
       Grading.last =Main.cursor1.GetString("lname")
   Grading.first =  Main.cursor1.GetString("fname")
   Grading.sub1 =  subj
   Grading.sec1 =  sec
   Grading.attendance1 = Main.cursor1.GetString("attendance")
   Grading.per = rb
   Grading.quiztot =  Main.cursor1.GetString("quizTotal")
   Grading.assTot =  Main.cursor1.GetString("assTotal")
   Grading.project =  Main.cursor1.GetString("project")
   Grading.exam =  Main.cursor1.GetString("exam")
   Grading.grade=  Main.cursor1.GetString("grade")
     StartActivity("grading")
   
     Next
End Sub

My code above shows only the last record of my database. All I wanted is that if I select the row, it will show the correct selected field to my next display but it ended up showing the last record of my database. Thanks
 

Pantelis Loizou

Member
Licensed User
Hallo everyone! Need some help...Is there any way in the existing library where i can use the functionality of multiple row selection? E.g. Deletion of muliple rows instead of choosing one by one! Any info would be greatly appreciated. Thanx!
 
Top