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

Roberto P.

Well-Known Member
Licensed User
Hello to all,
when I click on a particular cell change color (ok it works), but how much change the line resets the standard color.
Is there a way to preserve the color and prevent spade changed the color of the cell?

upload_2015-11-21_22-52-26.png


upload_2015-11-21_22-55-11.png


Use this function for change the color

Sub Table1_CellClick(Col As Int, Row As Int)

If mTableOpenOrder.visibleRows.ContainsKey(Row) Then
Dim lbls() As Label
lbls = mTableOpenOrder. visibleRows.get(Row)
lbls(3).Color = Colors.Green
End If

end sub
 

Attachments

  • upload_2015-11-21_22-54-14.png
    upload_2015-11-21_22-54-14.png
    18.8 KB · Views: 69

Roberto P.

Well-Known Member
Licensed User
Hello Erel
thank you, I understand.
But custom listview has some features that I need:

- Sorting columns
- Horizontal scrolling

Find an alternative solution.
Greetings
 

staticmike

Member
Licensed 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
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:

klaus

Expert
Licensed User
Which version of the Table class are you using ?
The last version is 1.43.
In this version the row colors are properties, like:
Table1.RowCol1 = Colors.Red
Table1.RowCol2 = Colors.Blue
 
Last edited:

deyvitm

Member
Licensed 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
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
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...
 
Top