Skip to main content

RepositoryItemLookUpEdit.AcceptEditorTextAsNewValue Property

Gets or sets whether a custom value (a value that is not present in the lookup data source) that is entered in the edit box is accepted by the editor (when the value is validated and editor loses focus). This property supports ComboBox mode for the lookup editor.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.2.dll

Declaration

[DefaultValue(DefaultBoolean.Default)]
[DXCategory("Behavior")]
public DefaultBoolean AcceptEditorTextAsNewValue { get; set; }

Property Value

Type Default Description
DefaultBoolean Default

A value that specifies if custom values are accepted by the editor. The DefaultBoolean.Default property value is equivalent to True.

Available values:

Name Description Return Value
True

The value is true.

0

False

The value is false.

1

Default

The value is specified by a global option or a higher-level object.

2

Remarks

The AcceptEditorTextAsNewValue property supports ComboBox mode for the lookup editor. See the ComboBox Mode - Enter New Values topic to learn more.

Example

This example shows the use of LookupEdit and GridLookupEdit controls in ComboBox mode, in which the editors accept any text in the edit box. An end-user can select an existing value from a lookup data source or type any string. The text entered is saved in the editor’s edit value when the editor loses focus.

Lookup data sources for the LookupEdit and GridLookupEdit controls are an array of strings and a list of business objects, respectively.

ComboBox mode is enabled when the following conditions are met:

  • the AcceptEditorTextAsNewValue property enables entering custom text in the edit box.

  • the ValueMember and DisplayMember properties are set to an empty string (see the LookupEdit control initialization), or to the same field in the lookup data source (see the GridLookupEdit control initialization).

  • the TextEditStyle property is set to Standard to enable text editing.

lookup-comboboxmode-example-form.png

View Example

using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lookup_ComboboxMode {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            initLookupEdit();
            initGridLookupEdit();
        }


        void initLookupEdit() {
            lookUpEdit1.EditValueChanged += LookUpEdit1_EditValueChanged; ;
            lookUpEdit1.Properties.NullText = "(select or type value)";

            string[] colors = new string[] {
                "Yellow", "Red", "Green", "Black", "White"
            };

            lookUpEdit1.Properties.DataSource = colors;
            lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
            lookUpEdit1.Properties.AcceptEditorTextAsNewValue = DevExpress.Utils.DefaultBoolean.Default; //Default is equivalent to True for LookupEdit control
        }

        void initGridLookupEdit() {
            gridLookUpEdit1.EditValueChanged += LookUpEdit1_EditValueChanged;
            gridLookUpEdit1.Properties.NullText = "(select or type value)";

            List<Product> products = new List<Product> {
                new Product(){ ProductName="Chang" },
                new Product(){ ProductName="Ipoh Coffee" },
                new Product(){ ProductName="Ravioli Angelo" },
                new Product(){ ProductName="Filo Mix" },
                new Product(){ ProductName="Tunnbröd" },
                new Product(){ ProductName="Konbu" },
                new Product(){ ProductName="Boston Crab Meat" }
            };

            gridLookUpEdit1.Properties.DataSource = products;
            gridLookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
            gridLookUpEdit1.Properties.AcceptEditorTextAsNewValue = DevExpress.Utils.DefaultBoolean.True;
            gridLookUpEdit1.Properties.ValueMember = "ProductName";
            gridLookUpEdit1.Properties.DisplayMember = gridLookUpEdit1.Properties.ValueMember;
            gridLookUpEdit1.ProcessNewValue += GridLookUpEdit1_ProcessNewValue;

        }

        Dictionary<LookUpEditBase, LabelControl> labelDictionaryCore;
        Dictionary<LookUpEditBase, LabelControl> labelDictionary {
            get {
                if (labelDictionaryCore == null) {
                    labelDictionaryCore = new Dictionary<LookUpEditBase, LabelControl>();
                    labelDictionaryCore.Add(lookUpEdit1, labelControl1);
                    labelDictionaryCore.Add(gridLookUpEdit1, labelControl2);
                }
                return labelDictionaryCore;
            }
        }

        private void LookUpEdit1_EditValueChanged(object sender, EventArgs e) {
            //Display lookup editor's current value.
            LookUpEditBase lookupEditor = sender as LookUpEditBase;
            if (lookupEditor == null) return;
            LabelControl label = labelDictionary[lookupEditor];
            if (label == null) return;
            if (lookupEditor.EditValue == null)
                label.Text = "Current EditValue: null";
            else
                label.Text = "Current EditValue: " + lookupEditor.EditValue.ToString();
        }

        private void GridLookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e) {
            //Add new values to GridLookUpEdit control's DataSource.
            GridLookUpEdit gridLookup = sender as GridLookUpEdit;
            if (e.DisplayValue == null) return;
            string newValue = e.DisplayValue.ToString();
            if (newValue == String.Empty) return;
            if (MessageBox.Show(this, "Add '" + newValue + "' to list?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) {
                List<Product> ds = gridLookup.Properties.DataSource as List<Product>;
                ds.Add(new Product { ProductName = newValue });
                e.Handled = true;
            }
        }
    }

    public class Product {
        public string ProductName { get; set; }
    }


}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AcceptEditorTextAsNewValue property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also