Android Question B4xtable column index

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
B4X:
Dim c As B4XTableColumn = B4XTable1.GetColumn(ColumnId)
Dim index As Int = B4XTable1.Columns.IndexOf(c)
Thank you @Erel
But index in your code always returns 0 for my table
My table snapshot is attached
b4xtablecolumnindex.jpg
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime 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.
 

Attachments

  • example.zip
    9.3 KB · Views: 70
Upvote 0

jimmyF

Active Member
Licensed User
But index in your code always returns 0 for my table
My table snapshot is attached
b4xtablecolumnindex-jpg.81423

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

-j
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you change these lines from:
B4X:
B4XTable1.AddColumn("Name",B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Name",B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Name",B4XTable1.COLUMN_TYPE_TEXT)
to:
B4X:
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.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime 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.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime 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.
It can has more columns with the same title
Please check attached example above
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Correct code:
B4X:
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).
 
Upvote 0
Top