Windows Develop Bookmark and Share   
 index > Windows Forms General > DropDownList, Autocomplete, Tab gives unexpected behavior
 

DropDownList, Autocomplete, Tab gives unexpected behavior

Lets say you have a list:
State
Straight
Street
Stroodle

In the combobox, you type "stre"
Street is selected
You hit Tab
As the next control is selected, you notice Straight is selected, not Street.

It seems that the last letter you typed, "e" is lost. However if you hit Enter before hitting Tab, the selection sticks.

Is this behavior by design or is there at least a way to have Tab keep the selection made by typing/autocomplete?

The combobox:
Me.cb.DropDownStyle = ComboBoxStyle.DropDownList
Me.cb.AutoCompleteSource = AutoCompleteSource.ListItems
Me.cb.AutoCompleteMode = AutoCompleteMode.SuggestAppend
Me.cb.DataSource = dt
Jason Honingford  Tuesday, March 25, 2008 5:49 PM

Hi Jason Honingford,

Based on my understanding, you said that when you type "stre" then "Street" was selected, and hit Tab, so the ComboBox lose the focus and the "Straight" was selected. You want the "Street" to be selected, right ? If I have misunderstood you, please feel free to tell me, thanks.

After several times testing, I really cannot reproduce your issue. The following is the code I used to do the testing.

Code Snippet

Public Sub New()

InitializeComponent()

img = Properties.Resources.Destination

Me.comboBox1.DisplayMember = "Name"

Me.comboBox1.ValueMember = "ID"

Me.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend

Me.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList

Me.comboBox1.DataSource = LoadData()

End Sub

Private Function LoadData() As DataTable

Dim dt As New DataTable("TestTable")

dt.Columns.Add("ID", GetType(Integer))

dt.Columns.Add("Name", GetType(String))

dt.Rows.Add(1, "Roy")

dt.Rows.Add(2, "Street")

dt.Rows.Add(3, "Strange")

dt.Rows.Add(4, "Solid")

Return dt

End Function

Regards,

Roy Zhou

Roy Zhou - MSFT  Friday, March 28, 2008 9:27 AM

Hi Jason Honingford,

Based on my understanding, you said that when you type "stre" then "Street" was selected, and hit Tab, so the ComboBox lose the focus and the "Straight" was selected. You want the "Street" to be selected, right ? If I have misunderstood you, please feel free to tell me, thanks.

After several times testing, I really cannot reproduce your issue. The following is the code I used to do the testing.

Code Snippet

Public Sub New()

InitializeComponent()

img = Properties.Resources.Destination

Me.comboBox1.DisplayMember = "Name"

Me.comboBox1.ValueMember = "ID"

Me.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend

Me.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList

Me.comboBox1.DataSource = LoadData()

End Sub

Private Function LoadData() As DataTable

Dim dt As New DataTable("TestTable")

dt.Columns.Add("ID", GetType(Integer))

dt.Columns.Add("Name", GetType(String))

dt.Rows.Add(1, "Roy")

dt.Rows.Add(2, "Street")

dt.Rows.Add(3, "Strange")

dt.Rows.Add(4, "Solid")

Return dt

End Function

Regards,

Roy Zhou

Roy Zhou - MSFT  Friday, March 28, 2008 9:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Associating a File Type To An Application
• OpenFileDialog Working directory?
• Convert DBCS to Unicode and Viceversa
• WebBrowser - how to get SelectedText ?
• UI like this, how can I get start ?
• Get font type from text file or printer setting
• Send http request without webbrowser
• invalid menu handle
• treeview get node select
• Help with Listview component