I’m practicing some with the listbox and I’m trying to figure out how to add multiple bits of information from text fields (inputs from the user) into the listbox. So far I know how to add two columns worth of information, but I’m stuck on how to add 3 or more columns for one row. This is the code I know so far:
I’ve also adjusted the number of columns in the inspector. I would like to add other columns for more information, but I’m not sure how to do that. Is there a general Xojo code structure to reference regarding this? I searched the Xojo documents, but I only say literature for Adding Rows.
If retrieving the info from a database (as your example code suggests), it’s basically a case of adding the new column name: A) when you retrieve the RecordSet results, and B) when you add the row to the ListBox.
Obviously, you will also need to do the same thing (add the new column name) when adding new entries to the database (as opposed to retrieving them) - otherwise you will be trying to retrieve something which doesn’t yet exist
I added this code to the Add button, but still the same issue happens.
Dim rec As DatabaseRecord
rec = New DatabaseRecord
rec.Column("id") = supidfield.Text
rec.Column("company") = SupCompField.Text
rec.Column("city") = cityfield.Text
MyDatabase.InsertRecord("supplierinfo", rec)
If MyDatabase.Error Then
MsgBox MyDatabase.ErrorMessage
Else
MyDatabase.Commit
Populate
End If
dim suppFolder as FolderItem = SpecialFolder.ApplicationData.Child(App.ExecutableFile.Name)
if not suppFolder.Exists then suppFolder.CreateAsFolder
MyDBFile = suppFolder.Child("Ch17.sqlite")
From the Language Reference on Recordset (2nd example)
Generic means of filling a listbox from a recordset. Not necessarily what you want but a good method to study.
[code]Sub PopulateListBox(dataList As Listbox, rs As RecordSet)
If rs Is Nil Then Return
// set up listbox state for population
dataList.DeleteAllRows
dataList.Columncount = rs.Fieldcount
// Add the DB columns as the headers for the ListBox
dataList.ColumnCount = rs.FieldCount
dataList.Column(-1).WidthExpression = “100”
For i As Integer = 0 To rs.FieldCount-1
dataList.Heading(i) = rs.IdxField(i+1).Name
Next
// Add the data from the table
While Not rs.EOF
dataList.AddRow("")
For i As Integer = 0 To rs.FieldCount-1
dataList.Cell(dataList.LastIndex, i) = rs.IdxField(i+1).StringValue
Next
rs.MoveNext