Android Question B4xtable column index

HAH

Well-Known Member
Licensed User
How to get the column index (not columnid) of b4xtable cell clicked event?
 

HAH

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

HAH

Well-Known 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.
 

Attachments

jimmyF

Active Member
Licensed User
But index in your code always returns 0 for my table
My table snapshot is attached
If all your columns have the same name then perhaps you should consider using the CustomListView rather than a table.

-j
 

Mahares

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

HAH

Well-Known 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.
 

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.
 

HAH

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.
It can has more columns with the same title
Please check attached example above
 

Erel

Administrator
Staff member
Licensed 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).
 
Top