Skip to main content
A newer version of this page is available. .

Lookup Editors

  • 9 minutes to read

Data Lookups

The DevExpress WinForms Subscription includes four lookup controls. Lookups are data-bound editors that display data source records in their dropdowns. Users can select one item (record) at a time. Users cannot edit records in the dropdown.

Standard Lookup

LookUpEdit is a text box editor with a dropdown panel that displays data in a simple table layout.

WinForms LookUp Editor

Run Demo: LookUp Edit

Grid-based Lookup

GridLookUpEdit is a lookup editor that embeds the Data Grid within the dropdown. With the Data Grid’s countless visualization and data presentation options, you have total control over the lookup’s UI/UX.

WinForms GridLookUp Editor

Run Demo: Grid LookUp

SearchLookUpEdit is a grid-based lookup with an embedded Find Panel. Unlike the GridLookUpEdit, this editor supports Instant Feedback mode, but does not allow users to enter values in the text box.

WinForms SearchLookUp Editor

Run Demo: LookUp with Search

TreeList-based Lookup

TreeListLookUpEdit is a lookup editor that embeds the Tree List control within the dropdown. Users can select values form hierarchical lists.

WinForms TreeListLookUp Editor

Run Demo: TreeList LookUp

Feature Matrix

Lookup Grid Lookup TreeList Lookup Search Lookup
In-Place Mode (use within data-aware controls) yes yes yes yes
Resizable Dropdown Window yes yes yes yes
Multiple Columns yes yes yes yes
Unbound Columns yes yes yes yes
Show/Hide Horizontal and Vertical Lines yes yes yes yes
Insert New Records/Values yes yes yes yes
Auto-Complete yes yes yes yes
Case Sensitive Search yes yes yes yes
Sorting yes yes yes yes
Display Data in Table Layout yes yes yes yes
Auto-Suggest Mode yes yes no yes
Data Aggregation (Summaries) no yes yes yes
Arrange Columns into Bands no yes yes yes
Row Auto Height no yes no yes
Grouping no yes no yes
Server Mode (Optimized Data Loading) no yes no yes
Instant Feedback UI no no no yes
Auto-Filter Row no yes yes yes
Find Panel no no no yes
Present Records as Tiles (Table, List, Kanban Board) no yes no yes
Hierarchical Data Structures no no yes no

Note

Use the PopupContainerEdit control if you need functionality that is not supported by lookup editors. This control allows you to display any controls within its popup window.

How to Use a PopupContainerEdit to Create an Editable Grid-based Lookup

Bind to Data

Lookups are data-bound controls. Use the following properties to bind a lookup editor to a data source:

  • DataSource – Specifies the source of records.
  • DisplayMember – The data source field, whose values are visible to users. A value from this field is displayed in the lookup’s text box when a user selects a record.
  • ValueMember – The data source field with unique/key values. A value from this data field is assigned to the lookup’s EditValue property when a user selects a record.

Important

When a lookup editor is used to edit cell values in the Data Grid, the type of the ValueMember field must match the type of the field assigned to the grid’s lookup column (GridColumn.FieldName). Enable the lookup’s ThrowExceptionOnInvalidLookUpEditValueType option to detect data type issues.

Use the lookup’s smart tag menu to bind it to data.

Main Lookup Settings in the Editor's Smart Tag Menu

The following example shows how to bind a lookup editor to data created at runtime:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

public partial class Form1 : DevExpress.XtraEditors.XtraForm {
    public Form1() {
        InitializeComponent();
        // Binds the lookup to data.
        lookUpEdit1.Properties.DataSource = Employee.GetSampleData();
        // Sets the lookup's data fields.
        lookUpEdit1.Properties.DisplayMember = "FullName";
        lookUpEdit1.Properties.ValueMember = "ID";
        // Sets the lookup's value. Selects the first record.
        lookUpEdit1.EditValue = 0;
    }
}

public class Employee {
    int fID;
    public Employee(int iD, string firstName, string lastName) {
        fID = iD;
        FirstName = firstName;
        LastName = lastName;
    }
    public static List<Employee> GetSampleData() {
        return new List<Employee>() {
            new Employee(0, "Bart", "Arnaz"),
            new Employee(1, "Leah", "Simpson"),
            new Employee(2, "Arnold", "Schwartz"),
            new Employee(3, "William", "Zimmer"),
            new Employee(4, "Samantha", "Piper")
        };
    }
    // The 'ID' field must contain unique values.
    public int ID {
        get {
            return fID;
        }
    }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [Display(Order = -1)]
    public string FullName {
        get {
            return string.Format("{0} {1}", FirstName, LastName);
        }
    }
}

The image below shows the result.

WinForms Lookup Editor

See the following articles for more information:

Allow Users to Enter New Values

Set the lookup’s TextEditStyle property to Standard to allow users to type in the text box. Handle the ProcessNewValue event to parse entered values and add new records to the lookup’s data source.

Add New Values to LookUp Editor

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

public Form1() {
    InitializeComponent();
    // Binds the lookup to data.
    lookUpEdit1.Properties.DataSource = Task.GetSampleData();
    // Sets the lookup's data fields.
    lookUpEdit1.Properties.DisplayMember = "Caption";
    lookUpEdit1.Properties.ValueMember = "ID";
    // Sets the lookup's value.
    lookUpEdit1.EditValue = 0;
    // Enables adding new values.
    lookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;
    lookUpEdit1.ProcessNewValue += new ProcessNewValueEventHandler(this.lookUpEdit1_ProcessNewValue);
}
private void lookUpEdit1_ProcessNewValue(object sender, ProcessNewValueEventArgs e) {
    if((string)e.DisplayValue == String.Empty) return;
    List<Task> dataSource = (sender as LookUpEdit).Properties.DataSource as List<Task>;
    dataSource.Add(new Task(dataSource.Count) { Caption = (string)e.DisplayValue});
    e.Handled = true;
}

public class Task {
    int fID;
    public Task(int id) {
        fID = id;
        CreateDate = DateTime.Today;
    }
    [Display(Order = -1)]
    public int ID {
        get {
            return fID;
        }
    }
    public string Caption { get; set; }
    public DateTime CreateDate { get; set; }
    public static List<Task> GetSampleData() {
        return new List<Task>() {
            new Task(0){Caption = "Research", CreateDate = new DateTime(2022, 10, 15)},
            new Task(1){Caption = "UI Design", CreateDate = new DateTime(2022, 11, 5)},
            new Task(2){Caption = "Environment Setup", CreateDate = new DateTime(2022, 11, 10)},
            new Task(3){Caption = "Sprint 1", CreateDate = new DateTime(2022, 11, 11)},
            new Task(4){Caption = "Sprint 2", CreateDate = new DateTime(2022, 12, 12)},
            new Task(5){Caption = "Sprint 3", CreateDate = new DateTime(2023, 1, 10)},
            new Task(6){Caption = "Testing", CreateDate = new DateTime(2022, 2, 10)}
        };
    }
}

Note

The LookUpEdit and GridLookUpEdit support ComboBox mode. In this mode, the lookups behave as a standard ComboBox control. Read the following topic for detailed information: ComboBox Mode for LookUp Controls.

Cascading Lookups

Lookups can filter their values based on the currently selected values of other lookups. Read the following topic for detailed information: How to Implement Cascading Lookups.

LookupEdit-Cascading-animation.gif

Unbound Columns

Lookups can display columns that are not bound to data source fields.

AutoSuggest and AutoSearch

Lookups can filter their records or suggest matching values as users type.

demo-autosuggest

Read the corresponding sections in the LookUpEdit topic for detailed information and examples.

Custom Filter Expression

Handle the LookUpEdit’s PopupFilter event to specify a custom filter expression.

using DevExpress.Data.Filtering;
using DevExpress.XtraEditors.Controls;

private void LookUpEdit1_PopupFilter(object sender, PopupFilterEventArgs e)
{
    e.Criteria = CriteriaOperator.Parse(string.Format("DeliveryDate < '{0}'", DateTime.Today));
}

Examples

See Also