This documentation is archived and is not being maintained.

ComboBox.Text Property

Gets or sets the text of the currently selected item.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public string Text { get; set; }
/** @property */
public String get_Text ()

/** @property */
public void set_Text (String value)

public function get Text () : String

public function set Text (value : String)

<object Text="string" .../>

Property Value

A string, the default value is an empty string.

When there is no selected item and IsEditable is true, this is the text entered in the text box. When IsEditable if false, this value has no effect.

This example shows how the Text property can be used to set text into the TextBox when the control opens, before the user makes a selection.

<ComboBox Name="cb" Margin="10,10,3,3" Width="200" Height="30" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" 
             IsEditable="true" Text="Open Combo Box" IsReadOnly="true" 
             StaysOpenOnEdit="true" IsDropDownOpen="true">
        <ComboBoxItem>Spain - Item 0</ComboBoxItem>
        <ComboBoxItem>France - Item 1</ComboBoxItem>
        <ComboBoxItem>Peru - Item 2</ComboBoxItem>
        <ComboBoxItem>Mexico - Item 3</ComboBoxItem>
</ComboBox>

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
Show: