I have the feeling that not too many people are using WebListBoxes with DataSource against Postgres SQL, maybe I am wrong.
I have noticed this issue and maybe even reported (don’t remember) but it is now the time I have to deal with it again. It is about selected row in the list. Here is the scenario:
the WebPage has main WebListBox with DataSource (“on the shelf”), the list is build for certain search criteria, typically it would be something like a code that is selected from the drop down list box aka WebPopupMenu
the user would select row in the main list to see details of the record on the page, it could edit the record, delete or insert new one
the user could then select something else in the WebPopupMenu and the main list would be rebuild for a different code
now, if user selects original code from the WebPopupMenu the main list would show the previously selected row, however, the SelectedRowIndex would actually be -1
The problem: it appears that the row in the main list is selected but it is really not.
I have tried to set the SelectedRowIndex to -1 upon the build of the list yet it has no effect. Needless to say that this is a big issue considering that some WebPages in this WebApp have more than one WebListBox and everything is driven by selection of the row in the main list.
What can I do to reliably to ensure that the list upon refresh (DataLoad) will not show the previously selected row?
I’m sorry I don’t fully understand what you are saying.
It seems that you have pages with several weblistboxes.
I don’t understand “if user selects original code” for example.
If you can create a sample project, someone can take a look to see if something can be changed. If not, at least that could help create an Issue for Xojo to review and see if they can do something (bug, workaround, add feature).
Typically WebPopupMenu is used to display either name or code/name combination of the entity, ex: bank. Internally the entity has its own ID, Name, Code, and maybe some other properties. The underlying SQL query that build main list may use Code (not the ID) as the record identifier (done for some legacy reasons, basically this is an alternate primary key). So I was referring to user selecting entity from the lookup list aka WebPopupMenu which loads the main list. This is where I meant “… if user selects original code”.
In short, the WebListBox using DataSource is build dynamically depending on the item selected in the WebPopupMenu. User could conceivably select items in the WebPopupMenu back and forth. In the meantime user could click on rows in the WebListBox.
The point is that rebuilding WebListBox (be it via code or flipping items in the WebPopupMenu) results in showing previously selected row in the WebListBox.
Here is a different setup illustrating the same problem:
It looks to me that the last selected rows state is not cleared. Let’s say I have list A and list B.
List A has two rows, I click on 1st row in List A, this will load List B with 6 rows, I will select rows 3,4,5 in list B, so far so good.
Now I will click on 2nd row in List A which is going to load List B with different number of rows, let’s say I get 3 rows, nothing is selected in List B at this point - this is still good.
Now I will go back to List A and reselect 1st row, this will load dependent List B with 6 rows and the rows 3,4,5 in List B will show as selected. Why? I expect nothing to be selected at this point as I have reloaded List B.
Here is a little visual for the above scenario (sorry I can’t expose the actual screen as it is for confidentiality reasons but I hope you will get the idea)
I have tried setting SelectedRowIndex to -1 but that didn’t seem to take any effect.
I am not sure how to use CallLater in this context though, at least just yet.
Btw, I have just asked ChatGPT about that problem and CallLater came about as well. Still, I also use WebThread and was thinking that I am in the right place in the code to set SelectedRowIndex to -1 after data reload, but so far I can’t make it work. I will try to experiment with CallLater.