DESKTOP- Autofill textfields from selected row in Listbox

Im trying now to have it after I’ve created a new customer to the database it displays the info in my listbox but now i need it when i click on a customer in the listbox that it autofills in the data from the database to TextFields. Not sure what I’m going to need to do to accomplish this. Can someone point me in the right direction with an example or a link?

Thank you
Travis McBride

Store the rowid from the database in the RowTag of the listbox.
Now, when you change the row, read the RowTag and load the Database entry with this rowid into the textfields.

@Sascha S i believe I’m storing the Primary Key ID in my rowtag . can you show me an example of what you mean.

@Travis McBride , try something like that…

Dim sql As string
Dim rs as recordset

sql = "Select * from myTable where id = " + myListBox.cell(myListBox.listindex, column)  // Column = position of your Primary key

rs = App.myDb.SqlSelect( sql )

If rs <> nil and rs.recordcount > 0 then
   txtfield1.text = rs.field("myField").StringValue.DefineEncoding(Encodings.UTF8) // ...or other encoding...
.
.
.
end if

Put then into listbox.change event handler...



Exactly. :slight_smile:

But i recommend to check for EOF instead of the RecordCount. Not all kinds of Database Types in Xojo supporting RecordCount, i think.

[quote=167200:@Adelar Duarte]@Travis McBride , try something like that…

If rs <> nil and Not rs.EOF then

Yes Sascha, you are right. I’m use so much MySql… almost forget others SGDBs…

Thank’s

[quote=167200:@Adelar Duarte]@Travis McBride , try something like that…

[code]
Dim sql As string
Dim rs as recordset

sql = "Select * from myTable where id = " + myListBox.cell(myListBox.listindex, column) // Column = position of your Primary key

rs = App.myDb.SqlSelect( sql )

If rs <> nil and rs.recordcount > 0 then
txtfield1.text = rs.field(“myField”).StringValue.DefineEncoding(Encodings.UTF8) // …or other encoding…
.
.
.
end if

Put then into listbox.change event handler…

[/code][/quote]
Thank you all so much for that. i was having a brain fart yesterday at work but today I understand exactly what i need to do !!