471,072 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,072 software developers and data experts.

ComboBox Autocomplete feature

I wanted to implement an autocomplete feature on the combobox where you
would type in partial text and it would try to match it for you. It
doesn't exist in .Net yet, but I'm guessing it will in the next
version.

Here are instructions how to do it:

http://support.microsoft.com/default...b;en-us;320107

There is one bug, though.

If you click the expansion error and then type text into the dropdown
entry box to find a match entry, the new value will not be saved by the
ComboBox. For some reason even though the values are registered on the
SelectedIndexChanged event, the new selected values are lost by the
LostFocus event.

I found one solution that reset the values in the LostFocus event but
it didn't work for me. What did work for me was doing this:

Private Sub AutoComboBox_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
MyBase.SelectedIndexChanged
' Need to maintain the selected values internally due to
combobox selection bug
m_selectedIndex = Me.SelectedIndex
m_selectedValue = Me.SelectedValue
m_selectedText = Me.Text
End Sub

Which maintains the values internally upon the selectedIndexChanged
event. And then reset it in the LostFocus event:

Private Sub AutoComboBox_LostFocus(ByVal sender As Object, ByVal e
As System.EventArgs) Handles MyBase.LostFocus

' Need to set the selected values internally due to combobox
selection bug
Me.SelectedIndex = m_selectedIndex
Dim valType As Type = m_selectedValue.GetType()
Dim val2Type As Type = Me.SelectedValue.GetType()

If Not m_selectedValue Is Nothing And valType Is val2Type Then
Me.SelectedValue = m_selectedValue
End If
Me.Text = m_selectedText

End Sub

Nov 21 '05 #1
0 1551

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by Alex | last post: by
3 posts views Thread by RajW | last post: by
19 posts views Thread by Bernie Yaeger | last post: by
2 posts views Thread by Becker | last post: by
2 posts views Thread by Kalvin | last post: by
6 posts views Thread by ezyeric13 | last post: by
reply views Thread by =?Utf-8?B?UiBSZXllcw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.