Export (0) Print
Expand All

ToolStripComboBox Class

Represents a ToolStripComboBox that is properly rendered in a ToolStrip.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public class ToolStripComboBox : ToolStripControlHost
public class ToolStripComboBox extends ToolStripControlHost
public class ToolStripComboBox extends ToolStripControlHost
Not applicable.

ToolStripComboBox is the ComboBox optimized for hosting in a ToolStrip. A subset of the hosted control's properties and events are exposed at the ToolStripComboBox level, but the underlying ComboBox control is fully accessible through the ComboBox property.

A ToolStripComboBox displays an editing field combined with a ListBox, allowing the user to select from the list or to enter new text. By default, a ToolStripComboBox displays an edit field with a hidden drop-down list. The DropDownStyle property determines the style of combo box to display. You can enter a value that allows for a simple drop-down, where the list always displays, a drop-down list box, where the text portion is not editable and you must select an arrow to view the drop-down list box, or the default drop-down list box, where the text portion is editable and the user must press the arrow key to view the list. To always display a list that the user cannot edit, use a ListBox control.

To add objects to the list at run time, assign an array of object references with the AddRange method. The list then displays the default string value for each object. You can add individual objects with the Add method.

In addition to display and selection functionality, the ToolStripComboBox also provides features that enable you to efficiently add items to the ToolStripComboBox and to find text within the items of the list. The BeginUpdate and EndUpdate methods enable you to add a large number of items to the ToolStripComboBox without the control being repainted each time an item is added to the list. The FindString and FindStringExact methods enable you to search for an item in the list that contains a specific search string.

Use the SelectedIndex property to get or set the current item in the drop-down list, and use the SelectedItem property to get or set a reference to the current item in the drop-down list.

The following code example demonstrates a ToolStripComboBox with various property settings, including automatic completion.

using System;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public class Form1 : Form
    {
        private ToolStrip toolStrip1;
        private ToolStripComboBox toolStripComboBox1;
    
        public Form1()
        {
            InitializeComponent();
        }
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }

        private void InitializeComponent()
        {
            toolStrip1 = new System.Windows.Forms.ToolStrip();
            toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
            toolStrip1.SuspendLayout();
            SuspendLayout();
            // 
            // toolStrip1
            // 
            toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            toolStripComboBox1});
            toolStrip1.Location = new System.Drawing.Point(0, 0);
            toolStrip1.Name = "toolStrip1";
            toolStrip1.Size = new System.Drawing.Size(292, 25);
            toolStrip1.TabIndex = 0;
            toolStrip1.Text = "toolStrip1";
            // The following code example demonstrates the syntax for setting
            // various ToolStripComboBox properties.
            // 
            toolStripComboBox1.AutoCompleteCustomSource.AddRange(new string[] {
            "aaa",
            "bbb",
            "ccc"});
            toolStripComboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
            toolStripComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
            toolStripComboBox1.DropDownHeight = 110;
            toolStripComboBox1.DropDownWidth = 122;
            toolStripComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
            toolStripComboBox1.IntegralHeight = false;
            toolStripComboBox1.Items.AddRange(new object[] {
            "xxx",
            "yyy",
            "zzz"});
            toolStripComboBox1.MaxDropDownItems = 9;
            toolStripComboBox1.MergeAction = System.Windows.Forms.MergeAction.Insert;
            toolStripComboBox1.Name = "toolStripComboBox1";
            toolStripComboBox1.Size = new System.Drawing.Size(121, 25);
            toolStripComboBox1.Sorted = true;
            // 
            // Form1
            // 
            ClientSize = new System.Drawing.Size(292, 273);
            Controls.Add(toolStrip1);
            Name = "Form1";
            toolStrip1.ResumeLayout(false);
            toolStrip1.PerformLayout();
            ResumeLayout(false);
            PerformLayout();

        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft