I want to use the WebListBox.SearchCriteria but I;m having some trouble. Using the code below, it does search the box and find the correct answer. However, two things also happen -
The box only shows the one result instead of highlighting it and still showing the other WebListBox entries. How do I stop that behavior?
And more importantly, how do I find the row that the search has yielded the result on?
This code only works for the first line. The second, where I want to get the row number, does not return anything. How else to get the row selected?
I think you’ll have to do the search yourself, by looping through the rows to find the one that matches. Then you can select that row, scroll to it, etc. SearchCriteria always reduces the listbox to only rows that match and it sounds like it doesn’t highlight any of them. There is no correlation between the result set and the original contents. Ie., the row number from the original contents is not available to you.
The code below does not work after doing “WebListBox.SearchCriteria = xxx”
Bummer since it does work great, is fast etc, but cannot use it any further…
lstAccounts.RemoveAllRows
stAccounts.ColumnCount=3
lstAccounts.HasHeader =True
lstAccounts.HeaderAt(0)="Site"
lstAccounts.HeaderAt(1)="Acc"
lstAccounts.HeaderAt(2)="Site Name"
lstAccounts.ColumnWidths = "60, 60, 150" //, 90"
Dim Result As Integer = Session.SiteList.getAll(False, "siteno", False)
If Result > 0 Then
do until Session.SiteList.RsSiteList.EOF
Session.SiteList.FillVars
lstAccounts.AddRow (cstr(Session.SiteList.SiteID), cstr(Session.SiteList.Account), trim(Session.SiteList.SiteName) )
Session.SiteList.RsSiteList.MoveNext
loop
End If
Isn’t it sufficient to clear SearchCriteria? The data is all stored behind the scenes. Also, even if you reload manually, the SearchCriteria is still filtering the rows. So at minimum you have to set lstAccounts.SearchCriteria = "".
The bummer of it too is the String.Compare does not work correctly either!
I search for “Woking” and get “Yellowhead” LOL
Maybe I’m not doing it correctly?
Tim
For i As Integer = 0 to lstAccounts.RowCount -1
Dim Nme As String = trim(lstAccounts.CellTextAt(i, 2).StringValue)
Dim Res As Integer = nme.Compare( trim(SrchName))
If Res > 0 then
They are sorted by a different ID, not by the name. But I could sort first by name and try that. I just thought that String.Compare worked better than this…
First, When you use AddRow (as opposed to a DataSource) WebListBox creates an in-memory SQLite database for each session. If your database contains a lot of rows and data that isn’t unique per user, I suggest switching to a DataSource.
Second, the in-memory database includes a full-text index of all added data so that SearchCriteria can use the FTS 5 indexing terms for finding things, which translates under the hood to:
SELECT * FROM table WHERE field MATCH 'search term' ORDER BY rank;
(Xojo will have to clarify as I simply don’t remember the exact query)
Really, since string comparison is case insensitive and Compare defaults to insensitive, about the only reason to use Compare is if you want case sensitive comparisons.