Fill Listbox problem while typing on Windows

Hello,

I want to use a combobox for searching a database and the results should be displayed in the combobox as well. On macOS it works perfectly. But I have a problem on Windows: when I type in the listbox, the typing is deleted instantly. The combobox under Windows has another behavior than under macOS. It must be something with the DeleteAllRows.

This is my code in the combobox.TextChanged event:

[code]Sub TextChanged() Handles TextChanged
me.DeleteAllRows

//here is normaly my code for searching the database
me.addrow(“Entry 1”)
me.addrow(“Entry 2”)
me.addrow(“Entry 3”)
me.addrow(“Entry 4”)
me.addrow(“Entry 5”)
End Sub
[/code]

Is there any workaround for windows? Thank you.

@Christian Präger — Maybe if you try

dim s as String = me.Text me.DeleteAllRows me.Text = s

Thanks Stphane, but I had to go a little further.

I now use the KeyDown Event, because the the TextChanged event got fired again when I use “me.text = s”

So now my code looks like this:

[code]Select Case Asc(Key)
Case 31 // up arrow
Case 29 // Right arrow
Case 30 // Down arrow
Case 28 // Left arrow
Case 13 // CR
Case 127 //Delete
Case 8 //Backspace
Else
dim s as String = me.Text
me.DeleteAllRows

//here is normaly my code for searching the database
me.addrow(“Entry 1”)
me.addrow(“Entry 2”)
me.addrow(“Entry 3”)
me.addrow(“Entry 4”)
me.addrow(“Entry 5”)

me.Text = s
me.SelStart = 999 //set cursor to last position
End Select[/code]

The problem is, that the position of the cursor jumps to the front. So I had to use “me.SelStart = 999”. It’s not very elegant. So there comes another problem, when I want to change text something in between, but I can live with that at the moment.