Any WebListBox Search Sample?

Hello all,

I looked in the sample files but could not find any sample for using the WebListBox.SearchCriteria

I have tried it, and it does find the things it is looking for, the problem, in my case, appears to be that the Row Indexes or the weblistbox itself is not updated until after the function has completed.


/
//---- This part works ----//
grdAccounts.SearchCriteria = Me.Text
If grdAccounts.RowCount = 0 Then 
  MessageBox " Could not find " + Me.Text
  Return
  
End If


//----  Found one record ----//
Dim RowCount As Integer = grdAccounts.RowCount <<==== This returns a 1
Dim Row As Integer = grdAccounts.LastRowIndex   <<==== This returns a zero since it should be the first record.



//----  This does NOT work ----//
If grdAccounts.RowCount = 1 Then
  grdAccounts.SelectedRowIndex = Row
  grdAccounts.SelectedRowColor = Color.Blue
  grdAccounts.ScrollTo(0)
  
End If


Further, it appears the weblistbox is not updated which is why the coloring of the row does not work. It also throws off other code that is after this and relies on getting the data in the first field of the LastRowIndex.

This is making me wonder if I am doing this correctly or if some more code needs to be added so the WebListBox is updated on the fly?

Any ideas??
Thanks,

Tim

Are you using the WebListBox with or without DataSource?

Without DataSource this is how it works:
screencast2025-04-212PM-59-57-ezgif.com-video-to-gif-converter

With this code on the WebSearchField

Listbox1.SearchCriteria = me.Text

With DataSource, there is an example that ships with Xojo ā€˜Listbox with a Datasource’ that works like this:
screencast2025-04-213PM-04-33-ezgif.com-video-to-gif-converter

What do you want to do with ā€˜coloring of the row’?

Hello Alberto,

I am using without a data source.

Color it - of course… but, the problem appears to have more to do with the fact that the WebListBox is not updated until after the method is completed.

Tim

Why you want to color the row?
The result can be 0, 1 or multiple rows depending on the search.
Usually the user on the webpage selects the row if/when needed.

Hello Alberto,

Yes, I know that it. Did you see my code? It only wants to color it if there is only 1 row.

Again, I think it is a problem where the WebListBox itself is not update until after the search code is executed. It appears to be correct with the right row count (not just 1 row but multiple too) So eventhough the search says there are only 1, 4 or whatever number of rows, the reality is, when you try to do something with the row returned (in the case of 1 row) the actual data that is retrieved later references the original data that was in the first row.

Dim Row As Integer = grdAccounts.LastRowIndex   <<==== This returns a zero since it should be the first record.

I’ll make a sample when I get some time.

Try it yourself tho. Populate like 10 different rows with different data - maybe the first column just a number. Search so the 7’th Item is selected during the search. Then try to anything with would now be row 0. You’ll get the original data from what was entered in the beginning as row 0.

Tim

No, that is not the problem. SearchCriteria searches for matches and whatever does not match is not showing but still on the Listbox.

You may see only 1 row, but that row, unless is the real first row, is not row 0. If your search finds only row 0, you can SelectRowIndex = 0 there.

The search items do not convert the resulting rows to a different row number.

Try it yourself, add Press method to listbox, search for something that is not row 0 and the listbox only shows 1 result, then on Pressed check for the Row that you pressed, it will not be row 0.

For example: 1 to 100, searched for 50:


Note: I’m not saying that there are no bugs here, but what I was able to find by testing a little. Maybe a problem with original information and showing information. Depending on the example that you create, you can file a bug report.

Edit: maybe a bug or bugs with the relation of original listbox and searched listbox? For example what you say about LastRowIndex (new info) and other results are for the original listbox (content, actual row number, etc.)

My tests have shown that you are incorrect.

I’ll create a sample when I get time.
Tim

Looks like you are not understanding what I’m saying.

I’ll try to explain better, I hope is clear.

When you do a WebListBox.SearchCriteria, the listbox only shows the results of the search.
After the search LastRowIndex, RowCount, and I guess others, are giving results of this new limited Listbox (maybe only 1 record).
The Listbox still contains all the original records.
If you add a Press event and you click on the found record, it will not say Row 0 but the original Row number (on my screenshot above Row 49).

And that is why you can’t color your row. Row 0 can only by selected/colored if the first result is Row 0.
screencast2025-04-214PM-29-12-ezgif.com-resize

Hello Alberto,

OK, so you have the idea.

That is all exactly as I have seen.

BUT - I need to get the info from the ā€œlimitedā€ Listbox. There is no way to know what the actual row is - correct? Soooo how to get the info, the limited listbox row numbers?

Tim

Looks like a bug. I can’t figure a way to do that.
If you can create an issue for this.

1 Like

You guys do understand that the WebListBox always uses a DataSource, right? When you don’t define a DataSource, an in-memory SQLite database is created for each listbox and attached to it as if it were its DataSource. Because of that, it is asynchronous. So when you set the search criteria, the listbox is told to reload and the client side control requests its visible rows again.

Hi Greg,
So is there a way to accomplish what I am looking for?

Tim

Yes

What we should expect from Listbox1.CellTextAt(0,0) from this screen?

Or what code can we use to find which rows are shown here?

That’s what we can’t find. Thanks in advance.

Edit: Sample code that you can modify
WeblistboxSearch.xojo_binary_project.zip (9.7 KB)
the goal is to have code to show 50 on the dialog after first search and 10 after the second search CellTextAt(0,0) button.

Assuming nothing has changed (and based on how complex the code is that makes weblistbox work, I don’t think you can expect CellTextAt to behave the way it does on the desktop. The trick is that it’s the filtering and ordering of the DataSource that changes so that, if you were to scroll to another portion of a list that filtered is still hundreds of lines long, the correct portion of the list can still be retrieved. What this means is that CellTextAt would need to actually query the DataSource to get you that information which could be a single field out of thousands or even hundreds of thousands of rows.

Personally, I think it would be better for you to do your own DataSource in this case and apply any search criteria yourself. Then, if your very own row count method were to return 1, you’d be able to know that something special needed to be done. Basically you add your own SearchCriteria property to the object that represents your DataSource and just apply that to the query you use in the RowCount method as well as in the RowData method.

Hi Greg.

What you suggest is exactly how I did it. I was looking at refactoring to take advantage of the
built-in search, which I thought would be faster and less processor intense.

Is there a way to know which end processing takes place for code I write? That was another consideration - thinking it would take place on the client side.

Thanks!
Tim

If you’re writing code in Xojo, it always runs in the server. Only controls written with the WebSDK in typescript /javascript run code on the browser itself.

1 Like