### Create TableView with Textfield

This is an example of creating a tableview with columns populated from a database and having customized cells as textfields
to change the content.
The code is based on the ExecuteTableView subroutine as defined in code module DBUtils.
Sub ExecuteTableView2
`Public Sub ExecuteTableView2(sqlObj As SQL, Query As String, StringArgs() As String, Limit As Int, _
EditFields() As Int, _
TableView1 As TableView)
Log("ExecuteTableView: Query=" & Query & ", Args:"&StringArgs(0))
TableView1.Items.Clear
Dim cur As ResultSet
Dim colcnt As Int = -1
If StringArgs = Null Then
Dim StringArgs(0) As String
End If
Try
cur = sqlObj.ExecQuery2(Query, StringArgs)
colcnt = cur.ColumnCount
Catch
Log(LastException.Message)
Return
End Try
Dim cols As List
cols.Initialize
For i = 0 To colcnt - 1
cols.Add(cur.GetColumnName(i))
Next
TableView1.SetColumns(cols)
Do While cur.NextRow
Dim row(colcnt) As Object
For col = 0 To colcnt - 1
row(col) = cur.GetString2(col)
For i = 0 To EditFields.Length - 1
If EditFields(i) < colcnt Then
Dim tf As TextField
tf.Initialize("")
tf.Text = cur.GetString2(EditFields(i))
row(EditFields(i)) = tf
End If
Next
Next
TableView1.Items.Add(row)
If Limit > 0 AND TableView1.Items.Size >= Limit Then Exit
Loop
For i = 0 To EditFields.Length - 1
If EditFields(i) < colcnt Then TableView1.SetColumnSortable(EditFields(i), False)
Next
cur.Close
Log("ExecuteTableView: Size=" & TableView1.Items.Size)
End Sub`
Example
SQLite database with two tables Items and Projects. The tableview is filled by selecting Items for a given project.
The textview fill is defined as tvwItems
' Select the items and add to the customized tableview.
' Column nr 3 is a textfield, to be able to change items.
DBUtils.ExecuteTableView2(DBMod.sqlObj, _
"SELECT * FROM Items WHERE Project=? ORDER BY ?", _
Array As String(project, "ID"), _
0, _
Array As Int(3), _
tvwItems)

Changed: 2018-03-16 18:29, Category: TableView, File: T6C259M1877.htm, ID: 1877