Hi all seniors, after trying and playing (for learning purposes) with TableView tutorial, I managed to use the PostgreSQL database to populate the TableView but I failed trying to use the column name from "Select * from table" to populate the "SetColumns" and with the sample files from the TableView Tutorial, I also failed to get the SetColumnStyle(1, "-fx-alignment: CENTER;") to work on my code. Hoping I would seek some guidance over here. ps: #AdditionalJar: postgresql-42.6.0.jar is added to Main.
B4XMainPage:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private pgSQL As SQL
Private TableViewHD As TableView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
TableViewHD.SetColumns(Array As String("prod_line_id", "prod_line", "prod_line_desc"))
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
'xui.MsgboxAsync("Hello world!", "B4X")
Try
Dim connectionString As String = "jdbc:postgresql://localhost:5432/my_hd?user=postgres&password=Demo1234"
pgSQL.Initialize("org.postgresql.Driver", connectionString)
'Log("Connection successful!")
Dim rs As ResultSet = pgSQL.ExecQuery("SELECT * FROM product_line")
Do While rs.NextRow
Dim values(rs.ColumnCount) As Object
For i = 0 To rs.ColumnCount - 1
values(i) = rs.GetString2(i)
Next
TableViewHD.Items.Add(values)
Loop
rs.Close
pgSQL.Close
Catch
Log("Error: " & LastException.Message)
End Try
pgSQL.Close
End Sub