Android Question B4XTable-Setup Table with Fewer Columns Using QueryBuilder Without Redefining Columns

Mahares

Expert
Licensed User
Longtime User
I have a B4XTable with 3 columns using an array of columns like this:
B4X:
ColNames =Array As String("ID","Name", "Street")
For i= 0 To ColNames.Length -1
   If i=0 Then
      B4XCol(i) = B4XTable1.AddColumn(ColNames(i), B4XTable1.COLUMN_TYPE_NUMBERS)
   Else
      B4XCol(i) = B4XTable1.AddColumn(ColNames(i), B4XTable1.COLUMN_TYPE_TEXT)
   End If
   B4XCol(i).Width=ColWidthOriginal(i)
Next

Later I use QueryBuilder to populate the table with only 2 of the 3 columns. I can add the 2 columns B4XCol(1) and B4XCol(2) like this:
B4X:
B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Street", B4XTable1.COLUMN_TYPE_TEXT)
Is there a way to set up the columns using the corresponding array elements B4XCol(1) and B4XCol(2) instead of rewriting the entire 2 lines above
Thank you
 

epiCode

Active Member
Licensed User
If I understand correctly, you wish to hide column 1 (ID) without having to add other two columns again ?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
We are not talikng about hiding columns. I reuse the same B4XTable layout by removing the views and populating the table with a different set of columns. Instead of using something like this in the code:
B4X:
Root.RemoveAllViews
    Root.LoadLayout("2")  'Has B4XTable1
    B4XTable1.AddColumn("NAME", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("STREET", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.SetData(l)
I want to use the below code which does not seem to be possible:
B4X:
Root.RemoveAllViews
Root.LoadLayout("2")  'Has B4XTable1
    B4XTable1.AddColumn(B4XCol(1))
    B4XTable1.AddColumn(B4XCol(2))
    B4XTable1.SetData(l)


Added this to the post: If I use this it works, but I was hoping for the above code to work:
B4X:
B4XTable1.AddColumn(B4XColumns.Get(1), 1)   'B4XColumns is a list of the columns names
    B4XTable1.AddColumn(B4XColumns.Get(2), 1)
    B4XTable1.SetData(l)
Added this later: I can use this also. It works:
B4X:
Type MyTableCols( column As String, coltype As Int)  'in globals
    Private MyList As List[   'in globals
B4X:
Root.RemoveAllViews
    Root.LoadLayout("2") 
    Dim ct As MyTableCols =MyList.Get(1)
    B4XTable1.AddColumn(ct.column, ct.coltype)    'col name, col type
    Dim ct As MyTableCols =MyList.Get(2)  'MyList is a list of custom Type
    B4XTable1.AddColumn(ct.column, ct.coltype)
    B4XTable1.SetData(l)

I think the best solution is to do this. I will stick with it, unless someone has a better approach for what I was trying to achieve:
B4X:
Root.RemoveAllViews
    Root.LoadLayout("2")  'no need to use layout 3
    Dim c As B4XTableColumn=B4XCol(1)
    B4XTable1.AddColumn(c.Title, c.ColumnType)    'col name, col type
    Dim c As B4XTableColumn=B4XCol(2)
    B4XTable1.AddColumn(c.Title, c.ColumnType)    'col name, col type
    B4XTable1.SetData(l)
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…