This topic has not yet been rated - Rate this topic

ComboBox.IsEditable Property

Gets or sets a value that enables or disables editing of the text in text box of the ComboBox.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public bool IsEditable { get; set; }
<object IsEditable="bool" .../>

Property Value

Type: System.Boolean
true if the ComboBox can be edited; otherwise false. The default is false.

Identifier field

IsEditableProperty

Metadata properties set to true

None

The IsEditable and IsReadOnly properties specify how the ComboBox behaves when the user does one of the following:

  • Enters a string to select an item in the ComboBox.

  • Enters a string that does not correspond to an item in the ComboBox.

  • Selects part of the string that is in the text box.

  • Copies or pastes a value into the text box.

The following table describes the actions the user can and cannot take, depending on the values of IsEditable and IsReadOnly.

IsReadOnly is true

IsReadOnly is false

IsEditable is true

  • Cannot select an item in the ComboBox by entering a string.

  • Cannot enter a string that does not correspond to an item in the ComboBox.

  • Can select part of the string in the ComboBox text box.

  • Can copy the string in the ComboBox text box, but cannot paste a string into the ComboBox text box.

  • Can select an item in the ComboBox by entering a string.

  • Can enter a string that does not correspond to an item in the ComboBox.

  • Can select part of the string in the ComboBox text box.

  • Can copy or paste the string in the ComboBox text box.

IsEditable is false

  • Can select an item in the ComboBox by entering a string.

  • Cannot enter a string that does not correspond to an item in the ComboBox.

  • Cannot select part of the string in the ComboBox.

  • Cannot copy or paste the string in the ComboBox.

  • Can select an item in the ComboBox by entering a string.

  • Cannot enter a string that does not correspond to an item in the ComboBox.

  • Cannot select part of the string in the ComboBox.

  • Cannot copy or paste the string in the ComboBox.

When IsEditable is equal to false, the ComboBox uses a ContentPresenter to display the currently selected item; when IsEditable is equal to true, a TextBox is used for this purpose instead. Note that a TextBox only displays plain text, and that a ComboBoxItem may include non-plain text content, such as images.

The following examples create ComboBox controls that contain images as items instead of text. If the IsEditable property is set to true, the TextBox displays the value returned by the image's ToString method. To avoid a TextBox with unexpected text, use the TextSearch.Text and TextSearch.TextPath properties to assign text to be displayed.


<ComboBox IsEditable="true" TextSearch.TextPath="Name">
  <Image Name="Cat" Source="data\cat.png"/>
  <Image Name="Dog" Source="data\dog.png"/>
  <Image Name="Fish" Source="data\fish.png"/>
</ComboBox>



<ComboBox IsEditable="true">
  <Image TextSearch.Text="Cat" Source="data\cat.png"/>
  <Image TextSearch.Text="Dog" Source="data\dog.png"/>
  <Image TextSearch.Text="Fish" Source="data\fish.png"/>
</ComboBox>


Another solution is to use the DisplayMemberPath property. The drop-down control of the ComboBox will not display the images but will display the text you assigned.

The following example shows how to use DisplayMemberPath.



<ComboBox IsEditable="true" DisplayMemberPath="Name">
  <Image Name="CAT" Source="data\cat.png"/>
  <Image Name="DOG" Source="data\dog.png"/>
  <Image Name="FISH" Source="data\fish.png"/>
</ComboBox>


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Tiny Little Aero-template Bug
Here's something you probably never noticed: the default editable combox box template used for Aero has a bug; the ToggleButton contained in it has no background set. This leaves it transparent, so you must aim your mouse directly at the tiny little down-arrow before it will become active. Then the toggle will hilight, which changes the background so you can click on it.

If you aim inaccurately and you don't hit the tiny little down arrow, you wind up clicking in the background of the combo box, which just highlights the text - it does not drop down.This affects only Aero (not Classic, Luna or Royale), and it affects only the editable template. thus you must set IsEditable="true" to see this.

For some reason I don't understand, this behavior only seems to manifest on RDP connections.

It is possible to work around this; you just need to dig out the ToggleButton and give it a background. To find it, use the control's Template, and find the Grid named "Placement". The ToggleButton is one of its children. Only the Aero template has this grid, so if you can't find it, do nothing.