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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 4, 2012.

  1. solfinker

    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:
    Code:
    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.
     
  2. klaus

    klaus Expert Licensed User

  3. solfinker

    solfinker Member Licensed User

    Thank you.
    I suppose I'll keep up with the table class.
     
  4. jeffnooch

    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:


    Code:
    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
     
  5. klaus

    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: Mar 24, 2019
  6. jeffnooch

    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...
     
  7. klaus

    klaus Expert Licensed User

    You should add the labels at the same time you add the tables.
    Or do you also add tables above each other.
     
  8. ValDog

    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?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    This method is based on StringUtils.SaveCSV which writes the data to a file. You will need to create a temporary file and then read it.
     
  10. klaus

    klaus Expert Licensed User

    Why do you want to transform the table into a string?
     
  11. ValDog

    ValDog Active Member Licensed User

    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.
     
  12. klaus

    klaus Expert Licensed User

    Sorry, I don't understand.
    What kind of data do you have in the table, why not using the database directly ?
     
  13. ValDog

    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!
     
  14. slavko

    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
     
  15. klaus

    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.
     
  16. slavko

    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?
     
  17. klaus

    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.
    Code:
    Table1.Initialize(Me, "Table1"5Gravity.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, 00, pnlTable.Width, pnlTable.Height)  
      
    '    Table1.MultiSelect = True
        Table1.MultiSelect = False
        Table1.SortColumn = 
    False
        Table1.SingleLine = 
    False  
      
    '    FillTableFix
    '    FillTableSQLite
        FillTableCSV
     
  18. slavko

    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?
     

    Attached Files:

  19. slavko

    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?
     
  20. slavko

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice