WebListBox with WebDataSource

Looking at the example: WebListbox Datasource Example

If I add the event SelectionChanged to the ListBox1. I can get the SelectedRowIndex, but how do you relate that back to the rows datasource row or PrimaryKey value?

CellValueAt seems to be empty, and depending upon how the user resorted the list, SelectedRowIndex could be pointing to any data record.

What I do, since I have objects that represent database rows, I store the object as the row’s Tag. You should be able to store an object (or if you’re attached to a database a row id) in the row’s Tag and get them back with https://documentation.xojo.com/api/user_interface/web/weblistbox.html#weblistbox-rowtagat

Thinking about it now, it seems silly that we can’t get that WebListboxRowData object back out from the WebListbox. Someone should file a feature request :upside_down_face:

1 Like

Here’s an example project I built from ARGen that shows how to use WebDataSource with objects: Chinook_Web.xojo_xml_project

You’ll need the Chinook database from here: https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

1 Like

Are you aware of any solution to this?

As I’d outlined you can use ActiveRecord objects as RowTags. I do not know of anyone filing a ticket to request access to the WebListboxRowData object. You should do so if you’d like to take a different approach, but quickly looking it seems like what I described still works.

The SelectedRowIndex should be converted in the background to match the order of the last request. After the first request, it’ll be the default sort order. If the user sorts the rows, your data source is sent the sort order, so you re-pull the data.

Since you need to return the primary keys in the order that you pulled them, just keep that array around and query it.

1 Like