Android Question B4xtable column index

Discussion in 'Android Questions' started by HAH, Jun 17, 2019.

  1. HAH

    HAH Active Member Licensed User

    How to get the column index (not columnid) of b4xtable cell clicked event?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim c As B4XTableColumn = B4XTable1.GetColumn(ColumnId)
    Dim index As Int = B4XTable1.Columns.IndexOf(c)
     
    jimmyF, mangojack, HAH and 1 other person like this.
  3. HAH

    HAH Active Member Licensed User

    Thank you @Erel
    But index in your code always returns 0 for my table
    My table snapshot is attached
    b4xtablecolumnindex.jpg
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The code I posted returns the column index from the columns list. I'm not sure which index you are trying to get. It is better if you upload a small project.
     
  5. HAH

    HAH Active Member Licensed User

    Project example is attached.
    Clicking any cell, Always you'll get column index 0 according to your code above.
    I want it as this: if you clicked on Erel cell you should got index 1 and if you clicked on Hamied cell you should got index 2 and so on.
     

    Attached Files:

  6. jimmyF

    jimmyF Active Member Licensed User

    If all your columns have the same name then perhaps you should consider using the CustomListView rather than a table.

    -j
     
  7. Mahares

    Mahares Well Known Member Licensed User

    If you change these lines from:
    Code:
    B4XTable1.AddColumn("Name",B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "Name",B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "Name",B4XTable1.COLUMN_TYPE_TEXT)
    to:
    Code:
    B4XTable1.AddColumn("Name1",B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "Name2",B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "Name3",B4XTable1.COLUMN_TYPE_TEXT)
    It will work for you.
     
  8. HAH

    HAH Active Member Licensed User

    I want column index regardless of column title "columnid"
    In cellclicked event we get the row id perfectly, but column index no!
    My purpose is getting the column index from the table so I can iterate smoothly through the table columns, and i can call the column by index not name.
    I don't depend on titles, because my app is multilanguages, so it is a time consuming to depend on column titles.
     
  9. Mahares

    Mahares Well Known Member Licensed User

    You cannot have the same title for each column in B4XTable for it to work properly. It uses an in-memory SQLite database where you cannot have 2 identical column names.
     
  10. HAH

    HAH Active Member Licensed User

    It can has more columns with the same title
    Please check attached example above
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Correct code:
    Code:
    B4XTable1.AddColumn("Name1",B4XTable1.COLUMN_TYPE_TEXT).Title = "Name"
        B4XTable1.AddColumn(
    "Name2",B4XTable1.COLUMN_TYPE_TEXT).Title = "Name"
        B4XTable1.AddColumn(
    "Name3",B4XTable1.COLUMN_TYPE_TEXT).Title = "Name"
    By default the id and title are the same. You can change it. Note that the id is not related to the SQL column name (Column.SQLID returns the SQL column name).
     
    AnandGupta and HAH like this.
  12. HAH

    HAH Active Member Licensed User

    WOW great approach , thank you
     
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