WebListBox questions

Hello all,

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 -

  1. The box only shows the one result instead of highlighting it and still showing the other WebListBox entries. How do I stop that behavior?

  2. 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?

lstAccounts.SearchCriteria = SrchName
Row = lstAccounts.SelectedRowIndex

Thank you,
Tim

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.

Am having trouble re-loading the list too!

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 = "".

Thanks Tim,
That did clear it up so that it could be populated again.

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 
   

Are the rows sorted? Is “Yellowhead” the row after “Working”? You’re currently asking for a value that is greater than SrchName.

1 Like

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…

Tim

Assuming nme = “Yellowhead” and SrchName = “Working”, then it seems to be functioning correctly.

1 Like

@Tim_Seyfarth , I have some suggestions.

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)

I’m sorry Tim, I do not see how that is correct.

If I search for Woking and get Yellowhead, that is clearly not correct - What am I missing??
Tim

You are asking for a Nme value that is greater than SrchName. If SrchName is “Working”, then “Yellowhead” fits that requirement.

Res = Nme.Compare(SrchName)
Nme less than SrchName, Res < 0
Nme equals SrchName, Res = 0
Nme greater than SrchName, Res > 0

What kind of a match are you looking for? Exact match? Matches the beginning? Matches somewhere in the middle?

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.

Hmmm… used > 0 since Instr provides a numer greater than zero.

I’ll try that out!
Thanks,
Tim

Instr is now IndexOf and the test would be Res >= 0. Or you can skip all that and use String.Contains, which returns a boolean.

If Nme.Contains(SrchName) Then

1 Like

That works perfectly Tim.
Thank you!!
Tim