Skip to main content

ComboBox Mode - Enter New Values

  • 2 minutes to read

The LookUpEdit and GridLookUpEdit controls allow users to type in the text box and enter values that are not in the data source (ComboBox mode). The SearchLookUpEdit and TreeListLookUpEdit controls do not allow users to add new values.

Do the following to enable users to enter new values:

  • Set the lookup’s TextEditStyle property to Standard to allow users to type in the text box.
  • Set the ValueMember and DisplayMember properties to the same data field (with string values).

    Note

    Do not specify the ValueMember and DisplayMember properties (set them to an empty string instead) if a lookup is bound to an array of strings.

  • Enable the AcceptEditorTextAsNewValue option (AcceptEditorTextAsNewValue for a Grid Lookup). The lookup assigns a value entered by the user (that does not exist in the data source) to the EditValue property.

    Note

    Handle the ProcessNewValue event to parse entered values and add new records to the lookup’s data source. In inplace mode, you should always add new values to the lookup’s data source.

    Read the following topic for detailed information on how to add new values to the lookup’s data source: Lookups - How to Enter New Values and Post Them to Data Source.

Example - Lookup

This example shows how to switch the LookUpEdit control that displays an array of strings to ComboBox mode.

Add New Values - WinForms Lookup

using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;

// Binds the lookup to an array of strings.
lookUpEdit1.Properties.DataSource = new List<string>() {
  "London", "New York", "Tokyo", "Berlin" };
// Enables adding new values.
lookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;
lookUpEdit1.Properties.AcceptEditorTextAsNewValue = DefaultBoolean.True;

Example - Grid Lookup

This example shows how to switch the GridLookUpEdit control to ComboBox mode.

Add New Values - WinForms Grid Lookup

using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using System.ComponentModel.DataAnnotations;

// Binds the grid lookup to a list of data objects.
gridLookUpEdit1.Properties.DataSource = Department.Init();
gridLookUpEdit1.Properties.DisplayMember = "Name";
gridLookUpEdit1.Properties.ValueMember = "Name";
// Enables adding new values.
gridLookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;
gridLookUpEdit1.Properties.AcceptEditorTextAsNewValue = DefaultBoolean.True;
See Also