I am using the table example with a database. i need to use a field returned from the database as a column header for col2 3 etc. How can i do this to replace the headers? Also there may be more than 4 cols. i will not know in advance. how can i build the string in the array. I tried stringbuilder but that does not work it treats the string as one column
B4X:
Table1.SetHeader(Array As String("Prod Code", "Description", "Col2", "Col3","Col4"))
txt = "SELECT Field1, Field2, Field3 FROM MyTable"
Cursor1=SQL1.ExecQuery(txt)
Dim Col_Name(3) As String
For i=0 To Cursor1.ColumnCount-1
Col_Name(i)=Cursor1.GetColumnName(i)
Next
Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2))
Table1.SetHeader(Col_Name)
looking at the code, that is very close to what i need and looks like it will work for the array part. However ,
B4X:
Dim Col_Name(3) As String
...
...
Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2))
shows that the number of columns is known in advance
what i need is similar to
B4X:
Counter=cursor1.ColumnCount
Dim Col_Name(Counter) As String
for x= 0 to Counter
Col_Name1=Col_Name1 & Col_Name(x)
next
Col_Name = Array As String(Col_Name1)
Obviously this would not work but it should give you the idea of what i am trying to achieve.
Any ideas?
Dim Col_Name() As String
Dim tempList As String
For i=0 To yourCursor.ColumnCount-1
tempList=tempList & ",," & yourCursor.GetColumnName (i)
Next
Col_Name=Regex.Split (",,",tempList.SubString (2))
Table1.SetHeader(Col_Name)
Here is another solution where you do not need to know the number of columns in advance. You have choices:
B4X:
txt = "SELECT Field1, Field2, Field3 FROM MyTable"
Cursor1=SQL1.ExecQuery(txt)
Dim MyColCount As Int
MyColCount=Cursor1.ColumnCount
Dim Col_Name(MyColCount) As String
For i=0 To MyColCount-1
Col_Name(i)=Cursor1.GetColumnName(i)
Next
Table1.SetHeader(Col_Name)
Here is another solution where you do not need to know the number of columns in advance. You have choices:
B4X:
txt = "SELECT Field1, Field2, Field3 FROM MyTable"
Cursor1=SQL1.ExecQuery(txt)
Dim MyColCount As Int
MyColCount=Cursor1.ColumnCount
Dim Col_Name(MyColCount) As String
For i=0 To MyColCount-1
Col_Name(i)=Cursor1.GetColumnName(i)
Next
Table1.SetHeader(Col_Name)