Lookup Editors
- 8 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.
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.
Lookup with Integrated Search
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.
TreeList-based Lookup
TreeListLookUpEdit is a lookup editor that embeds the Tree List control within the dropdown. Users can select values form hierarchical lists.
Feature Matrix
Lookup | Grid Lookup | TreeList Lookup | Search Lookup | |
---|---|---|---|---|
In-Place Mode (use within data-aware controls) | ![]() |
![]() |
![]() |
![]() |
Resizable Dropdown Window | ![]() |
![]() |
![]() |
![]() |
Multiple Columns | ![]() |
![]() |
![]() |
![]() |
Unbound Columns | ![]() |
![]() |
![]() |
![]() |
Show/Hide Horizontal and Vertical Lines | ![]() |
![]() |
![]() |
![]() |
Insert New Records/Values | ![]() |
![]() |
![]() |
![]() |
Auto-Complete | ![]() |
![]() |
![]() |
![]() |
Case Sensitive Search | ![]() |
![]() |
![]() |
![]() |
Sorting | ![]() |
![]() |
![]() |
![]() |
Display Data in Table Layout | ![]() |
![]() |
![]() |
![]() |
Auto-Suggest Mode | ![]() |
![]() |
![]() |
![]() |
Data Aggregation (Summaries) | ![]() |
![]() |
![]() |
![]() |
Arrange Columns into Bands | ![]() |
![]() |
![]() |
![]() |
Grouping | ![]() |
![]() |
![]() |
![]() |
Server Mode (Optimized Data Loading) | ![]() |
![]() |
![]() |
![]() |
Instant Feedback UI | ![]() |
![]() |
![]() |
![]() |
Auto-Filter Row | ![]() |
![]() |
![]() |
![]() |
Find Panel | ![]() |
![]() |
![]() |
![]() |
Present Records as Tiles (Table, List, Kanban Board) | ![]() |
![]() |
![]() |
![]() |
Hierarchical Data Structures | ![]() |
![]() |
![]() |
![]() |
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.
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.
See the following articles for more information:
- LookUp Standard Binding (Simple Data Types)
- LookUp Advanced Binding (Business Objects)
- How to Bind LookUp to a Dictionary
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.
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.
Unbound Columns
Lookups can display columns that are not bound to data source fields.
LookUpEdit – Handle the RepositoryItemLookUpEdit.GetNotInListValue event.
GridLookUpEdit, SearchLookUpEdit – Use the Grid Unbound Columns feature.
TreeListLookUpEdit – Use the TreeList Unbound Columns feature.
AutoSuggest and AutoSearch
Lookups can filter their records or suggest matching values as users type.
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));
}