How to: Enable AutoComplete in ToolStrip Controls in Windows Forms

 

The following procedure combines a ToolStripLabel with a ToolStripComboBox that can be dropped down to show a list of items, such as recently visited Web sites. If the user types a character that matches the first character of one of the items in the list, the item is immediately displayed.

System_CAPS_ICON_note.jpg Note

Automatic completion works with ToolStrip controls in the same way that it works with traditional controls such as ComboBox and TextBox.

To enable AutoComplete in a ToolStrip control

  1. Create a ToolStrip control and add items to it.

    ToolStrip1 = New System.Windows.Forms.ToolStrip  
    ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem()_  
        {ToolStripLabel1, ToolStripComboBox1})  
    
    
  2. Set the Overflow property of the label and the combo box to Never so that the list is always available regardless of the form's size.

    ToolStripLabel1.Overflow = _  
        System.Windows.Forms.ToolStripItemOverflow.Never  
    ToolStripComboBox1.Overflow = _  
        System.Windows.Forms.ToolStripItemOverflow.Never  
    
    
  3. Add words to the Items collection of the ToolStripComboBox control.

    ToolStripComboBox1.Items.AddRange(New Object() {"First Item", _  
        "Second Item", "Third Item"})  
    
    
    
  4. Set the AutoCompleteMode property of the combo box to Append.

    ToolStripComboBox1.AutoCompleteMode = _  
        System.Windows.Forms.AutoCompleteMode.Append  
    
    
  5. Set the AutoCompleteSource property of the combo box to ListItems.

    ToolStripComboBox1.AutoCompleteSource = _  
        System.Windows.Forms.AutoCompleteSource.ListItems  
    
    

ToolStrip
ToolStripLabel
ToolStripComboBox
AutoCompleteMode
AutoCompleteSource
ToolStrip Control Overview
ToolStrip Control Architecture
ToolStrip Technology Summary

Show: