AutoScroll listbox as I type

  • Thread starter Thread starter Selva Chinnasamy
  • Start date Start date
S

Selva Chinnasamy

I like to implement auto scrolling to the best match in the listbox as I
type.
Your response is highly appreciated.

Selva
 
Hi Selva,

Soulds like you do not like the listbox builtin AutoScroll behavior, if so
how about the following workaround:

Dim searchChars As String
...
Private Sub ListBox1_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyUp
searchChars += Chr(e.KeyValue)
ListBox1.SelectedIndex = ListBox1.FindString(searchChars)
End Sub

Private Sub ListBox1_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress
e.Handled = True
End Sub

By the way, you may need to use a timer to clean the searchChars string
once per second(or in a more duration time).

Wish this help!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Gary, Thanks for your reply. I have already tried the steps that you have
shown below.

I have attached debug statements below,

I wanted to search for screen "set".

As soon as I type 2nd char "E" even though the keypress Event finds the
right screen, event SelectedIndexChanged is excuted after handling the
Keypress event, which makes to search for screens starting with "E" instead
of "SE".


Search for : s

Event SelectedIndexChanged. Current Screen : SealerSelectFlapPosition
Event KeyPress. Current Screen :SealerSelectFlapPosition
Event SelectedIndexChanged. Current Screen : SealerWetnessSelect

Search for : se
Event SelectedIndexChanged. Current Screen : SealerSelectFlapPosition
Event KeyPress. Current Screen :SealerSelectFlapPosition
Event SelectedIndexChanged. Current Screen : EndSession

Search for : set
Event SelectedIndexChanged. Current Screen : SetupAutoFeederTimeout
Event KeyPress. Current Screen :SetupAutoFeederTimeout
Event SelectedIndexChanged. Current Screen : TechDataSuperRpt


Your response is greatly appreciated.

Selva
 
Gary, I found the solution for the problem by letting the OS know that I have
already handled the event.

I have added the following in KeyPress Event

e.Handled = True

Selva
 
That's great, Selva!

Have a nice day!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top