Scrolling listbox to a supplied search item

How does one code scrolling (moving the current selection) to a position in a listbox based on an entry in a search box? Thank you for any help.

set the ScrollPosition and/or the SelectedRowIndex.

1 Like

You also can center the found Row (vertically of course).

Is your question resolved ?

1 Like

Sadly, I haven’t found a solution to my problem.Given the Populate method below, I now set up a btnFind, that when pressed, will pick up the data in a search textfield that will be used to find and focus on the appropriate row in the listbox. Thanks much.

db = New SqLiteDatabase
var f as FolderItem = SpecialFolder.Resource("bisoogo.sqlite")

if f <> nil and f.Exists then
  try
    db.DatabaseFile = f
    if db.Connect then
      var rs as RowSet = db.SelectSQL("select * from meta")
      if rs <> Nil and not rs.AfterLastRow then
        For each r as DatabaseRow in rs
          Listbox1.AddRow rs.Column("meta_id").StringValue
        next
      end if
    end if
  Catch e as DatabaseException
    System.DebugLog e.Message
  end try
end if

in the textchanged event of the textfield: (top of my head code in API1 terms…)


if me.text > "" then
for x as integer = 0 to listbox1.listcount-1
if instr(listbox1.list(x),me.text) > 0 then
listbox1.scrollposition = x
exit
end if
next

end if
1 Like

Hello, I get the logic! I’m getting errors on " instr " and " list ". What would their new equivalent terms be? Thanks again.

Error on " list ": Type “DesktopListBox” has no member named “list”

Error on " IndexOf ": There is more than one method with this name " IndexOf " but this does not atch any of the available signatures.

if txtSearch.text > "" then
  for x as integer = 0 to Listbox1.RowCount - 1
    if IndexOf(Listbox1.list(x),txtSearch.text) > 0 then
      Listbox1.ScrollPosition = x
      exit
    end if
  next
end if

This should do it.

if txtSearch.text > "" then
  for x as integer = 0 to Listbox1.LastRowIndex
    if Listbox1.CellTextAt(x, 0).IndexOf(txtSearch.text) > -1 then
      Listbox1.ScrollPosition = x
      Listbox1.SelectedRowIndex = x
      exit
    end if
  next
end if
2 Likes

Anthony,
OMG! It works! Thank you very much. Another hurdle hurdled. I’m staying with Xojo.

Happy to help. Don’t forget to mark a solution so others can quickly find it in the future.