Items in the ComboBox control are not selected while you type the first characters (814362)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
Beta Information This article discusses a Beta release of a Microsoft
product. The information in this article is provided as-is and is subject to
change without notice.
No formal product support is available from
Microsoft for this Beta product. For information about how to obtain support
for a Beta release, see the documentation that is included with the Beta
product files, or check the Web location from which you downloaded the release.
SYMPTOMSYou set the DropDownStyle property of the ComboBox control to DropDownList, and then type the first characters of the item in the ComboBox during run time. The item that is selected in the ComboBox does not match the characters that you type. The item that is
selected in the ComboBox is based on the last character that you type. For Example, if the
items in the ComboBox are red, oak, and rose, when you type ro in the ComboBox, the focus is on oak instead of rose.CAUSEThis problem occurs because the ComboBox search is based on one character instead of the complete
character set.WORKAROUNDTo work around this problem, add code that searches for
items with all the characters that you type in the ComboBox. The code must also select the item that closely matches all the
characters. To clear the search text at regular intervals, use a Timer control. To do this, follow these steps:
- In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, create a new Windows
application by using Visual Basic .NET, Visual Basic 2005, or Visual C# .NET.
By default,
Form1 is created. - From the toolbox, drag a Timer to Form1.
- In the Properties window, set the Enabled
property to True.
- Add the following statement to the variable declaration
section of the code:
Visual Basic .NET or Visual Basic 2005Dim searchstr As String Visual C# .NETstring searchstr; - Add the following code to the Load event
of Form1:
Visual Basic .NET or Visual Basic 2005'set the timer interval and start the timer
Timer1.Interval = 1000
Timer1.Start() Visual C# .NET//set the interval and start the timer
timer1.Interval =1000;
timer1.Start(); - Add the following code to the Tick event
of Timer1:
Visual Basic .NET or Visual Basic 2005'empty the string for every 1 seconds
searchstr = "" Visual C# .NET//empty the string for every 1 seconds
searchstr=""; - Add the following code to the KeyUp event
of ComboBox1:
Visual Basic .NET or Visual Basic 2005 searchstr = searchstr & Chr(e.KeyValue)
' If the Search string is greater than 1 then use custom logic
If searchstr.Length > 1 Then
Dim index As Integer
' Search the Item that matches the string typed
index = ComboBox1.FindString(searchstr)
' Select the Item in the Combo
ComboBox1.SelectedIndex = index
End If Visual C# .NET searchstr = searchstr + Convert.ToChar(e.KeyCode);
// If the Search string is greater than 1 then use custom logic
if (searchstr.Length > 1)
{
int index;
// Search the Item that matches the string typed
index=comboBox1.FindString(searchstr);
// Select the Item in the Combo
comboBox1.SelectedIndex=index;
}
STATUS This
behavior is by design.
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbCtrl kbControl kbProperties kbdisplay kbWindowsForms kbComboBox kbprb KB814362 kbAudDeveloper |
---|
|