Click here to Skip to main content
11,804,566 members (97,189 online)
Click here to Skip to main content

Automaticaly Match and Select ComboBox Item

, 2 Nov 2006 41.2K 473 14
Rate this:
Please Sign up or sign in to vote.
Automaticaly Select Item From a Combox as the String is entered


This is a very simple Article. As I was working in VB I used to use a Data Combox which used to match and select the Items in it as you type in the string. I don't know whether .Net has such One. I think the default combox box dos'nt has it. So I worte this code which would that process.

The Code

Match Flag
Dim Match as Boolean
TextChanged : First we will ckeck for the match flag which is set by the key press event. If its true then We will check the entered string with the items in the list by their length. Like Taking the entered string and matching it with the item only to the length of the Enterded string ie,Chand is entered, We will match It with the Item in List ChandraSekar as Chand - Chand.If a string Matches then it will be selected in the ComboBox and a select command will be sent for the remaining length of the string selected to the entered one.
Dim i As Short
      Dim Buffer As Short
      If Match = True Then
          For i = 0 To CmBx.Items.Count - 1
              Buffer = Len(CmBx.Text)
              If StrComp(UCase(CmBx.Text), UCase(VB.Left(CmBx.Items.Item(i), Buffer))) = 0 Then
                  CmBx.Text = CmBx.Items.Item(i)
                  System.Windows.Forms.SendKeys.Send("{left " & Len(CmBx.Text) - Buffer & "}+{End}")
                  Exit Sub
              End If
          Next i
      End If
KeyPressEvent : Here we check for the key entered. If the pressed key is DEL or BACKSPACE we set the match flag to false and send the DEL key if DEL key was pressed.
Dim KeyCode As Short = Asc(e.KeyChar)
       If KeyCode = 8 Or KeyCode = 13 Then
           If KeyCode = 13 Then
           End If
           Match = False
           Match = True
       End If

Sample Image - ASComboBox1.JPG

Sample Image - ASComboBox2.JPG

Sample Image - ASComboBox3.JPG

Sample Image - ASComboBox4.JPG


This is a simple code. The Logic is also not too Complicated. I wrote this code because I did'nt find any feature like this in the Combo Box Control. If there is any in it or there is any other Combo Box Control Providing it please let me Know.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

ChandraSekar Maheswaran
Web Developer
India India
Am Chandru. I'm a Software developer. Am concentrating Only on Microsoft Technologies more than others. Don't ask me why..! I usually write codes a lot.. I do them because I Like them. Am working in a software firm in India. i've done a Post Graduation in Computers.

You may also be interested in...

Comments and Discussions

GeneralSuggestion on better code flow Pin
munnje2-Nov-06 8:16
membermunnje2-Nov-06 8:16 
GeneralRe: Suggestion on better code flow Pin
ChandraSekar Maheswaran2-Nov-06 18:10
memberChandraSekar Maheswaran2-Nov-06 18:10 
GeneralToo many Pin
Jonathan [Darka]2-Nov-06 3:18
memberJonathan [Darka]2-Nov-06 3:18 
GeneralRe: Too many Pin
ChandraSekar Maheswaran2-Nov-06 18:08
memberChandraSekar Maheswaran2-Nov-06 18:08 
GeneralRe: Too many Pin
ChandraSekar Maheswaran2-Nov-06 18:15
memberChandraSekar Maheswaran2-Nov-06 18:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 2 Nov 2006
Article Copyright 2006 by ChandraSekar Maheswaran
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid