This documentation is archived and is not being maintained.

ComboBox.DropDownStyle Property

Gets or sets a value specifying the style of the combo box.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ComboBoxStyle DropDownStyle { get; set; }

Property Value

Type: System.Windows.Forms.ComboBoxStyle
One of the ComboBoxStyle values. The default is DropDown.


The assigned value is not one of the ComboBoxStyle values.

The DropDownStyle property specifies whether the list is always displayed or whether the list is displayed in a drop-down. The DropDownStyle property also specifies whether the text portion can be edited. See ComboBoxStyle for the available settings and their effects. There is no setting to always display the list and disallow entering a new value. To display a list to which no new values can be added, use a ListBox control.

The following code example demonstrates setting the DropDownStyle property. To run the example, paste the following code in a form. Call the InitializeComboBox method in the form's constructor or Load event.

	internal System.Windows.Forms.ComboBox ComboBox1;
	private string[] animals;

	// This method initializes the owner-drawn combo box. 
	// The drop-down width is set much wider than the size of the combo box 
	// to accomodate the large items in the list.  The drop-down style is set to  
	// ComboBox.DropDown, which requires the user to click on the arrow to  
	// see the list. 
	private void InitializeComboBox()
		this.ComboBox1 = new ComboBox();
		this.ComboBox1.DrawMode = 
		this.ComboBox1.Location = new System.Drawing.Point(10, 20);
		this.ComboBox1.Name = "ComboBox1";
		this.ComboBox1.Size = new System.Drawing.Size(100, 120);
		this.ComboBox1.DropDownWidth = 250;
		this.ComboBox1.TabIndex = 0;
		this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown;
		animals = new string[]{"Elephant", "c r o c o d i l e", "lion"};
		ComboBox1.DataSource = animals;

		// Hook up the MeasureItem and DrawItem events 
		this.ComboBox1.DrawItem += 
			new DrawItemEventHandler(ComboBox1_DrawItem);
		this.ComboBox1.MeasureItem += 
			new MeasureItemEventHandler(ComboBox1_MeasureItem);

	// If you set the Draw property to DrawMode.OwnerDrawVariable,  
	// you must handle the MeasureItem event. This event handler  
	// will set the height and width of each item before it is drawn.  
	private void ComboBox1_MeasureItem(object sender, 
		System.Windows.Forms.MeasureItemEventArgs e)

			case 0:
				e.ItemHeight = 45;
			case 1:
				e.ItemHeight = 20;
			case 2:
				e.ItemHeight = 35;
		e.ItemWidth = 260;


	// You must handle the DrawItem event for owner-drawn combo boxes.   
	// This event handler changes the color, size and font of an  
	// item based on its position in the array. 
	private void ComboBox1_DrawItem(object sender, 
		System.Windows.Forms.DrawItemEventArgs e)

		float size = 0;
		System.Drawing.Font myFont;
		FontFamily family = null;

		System.Drawing.Color animalColor = new System.Drawing.Color();
			case 0:
				size = 30;
				animalColor = System.Drawing.Color.Gray;
				family = FontFamily.GenericSansSerif;
			case 1:
				size = 10;
				animalColor = System.Drawing.Color.LawnGreen;
				family = FontFamily.GenericMonospace;
			case 2:
				size = 15;
				animalColor = System.Drawing.Color.Tan;
				family = FontFamily.GenericSansSerif;

		// Draw the background of the item.

		// Create a square filled with the animals color. Vary the size 
		// of the rectangle based on the length of the animals name.
		Rectangle rectangle = new Rectangle(2, e.Bounds.Top+2, 
				e.Bounds.Height, e.Bounds.Height-4);
		e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle);

		// Draw each string in the array, using a different size, color, 
		// and font for each item.
		myFont = new Font(family, size, FontStyle.Bold);
		e.Graphics.DrawString(animals[e.Index], myFont, System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X+rectangle.Width, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));

		// Draw the focus rectangle if the mouse hovers over an item.

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0