Selecting a listbox entry by typing into a textbox

Hi,
Is there a way to have a text box, where as you enter each letter, it will go to that area of list box entries and refine the choice as more text is added?

Sure. In fact, I do that in RegExRX with the character chart, but you have to code it yourself. Xojo has no automatic function for that.

The good news is, it’s pretty easy.

I do that recently, but for one character only --> The first entry that starts with that character. It was a bit like:

Key holds the last typed character,

in a Loop, search in Column(0) what cell contents that starts using the Key character,
once found, set the ListIndex value to the Loop indicia,
Return.

If you want to be able to type more characters, you have to think a little bit more.

Nota: my testing file have a magazine name/ issue number in Column(0), so I do that in Column(1).

The higher difficulty was to come with the design: typing the code was fast.

BTW: of course, if teh ListBox holds more than hundreds Rows, the search may come to take time…

Thanks Guys,

Kem, I downloaded the REGExRX but got confused, I am fairly new to this so sorry about the stupid questions.
Is there any documentation on how to set it up with XOJO? It seems to be a standalone program.

John.

[quote=199685:@John Cooper]Hi,
Is there a way to have a text box, where as you enter each letter, it will go to that area of list box entries and refine the choice as more text is added?[/quote]

What you describe sounds very much like what happens when you type something in Google. As you type along, several options are presented, all based on the beginning of the text in these options.

When you mention a Listbox, there are several ways to go about that. For instance, say the listbox contains
Apple
Avocado
Banana
Brocoli

If I type A, It could have the first A selected, or both Apple and Avocado. Then of course as soon as I enter a second letter, only one will be selected, if it corresponds to an option. But if I enter Pineapple, nothing will ever be selected. Have I understood right ?

Yes, thanks Michel. That is exactly what I am trying to achieve.

Wasn’t this called Autocomplete in Xojo IDE ?

What you need to do as text is entered/deleted, probably in the TextField TextChange event is :

  • Loop through the ListBox and check with Instr() if TextField.Text is the same as the content of the row.

Here is an example : select.xojo_binary_project

Tanks Emile, I will look at that one.

Hi Michel,

Thanks, that looks very helpful. I will work in it in the morning. 10:15 pm here so it is off to bed for now.

Thanks to everyone for helping out.

John.

I just realized the code I posted selected the presence of the text in any part of the cell (instr() > 0). It should instead be :

Sub TextChange() for i as integer = 0 to ListBox1.ListCount-1 if instr(ListBox1.Cell(i,0), me.text) = 1 then ListBox1.Selected(i) = True else ListBox1.Selected(i) = False end if next End Sub

That way only the beginning of the cell content is taken into account. I have corrected the project I posted.