[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Collapse]Editors and Simple Controls
    Included Controls and Components
   [Expand]Common Editor Features and Concepts
   [Collapse]Lookup Editors
     Lookup Editors and Main Settings
     Standard Binding (to Simple Data Types)
     Advanced Binding (to Business Objects)
     Using a Dictionary Lookup Data Source
     Combobox Mode - Allow Entering New Values
     Cascading Lookups
    Popup Container Editor
   [Expand]Token Edit Control
   [Expand]Breadcrumb Edit Control
   [Expand]Range Control
   [Expand]Image Slider
    Camera Control
    Templated ListBox Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Advanced Binding (to Business Objects)

This topic describes the specifics of binding a lookup editor to a business object.

Unlike the standard lookup mode, which means that the editor's edit value is of a simple data type (e.g., integer), the binding of the lookup editor to a business object employs its own business object identification mechanism. This mechanism implies that a business object has a key field(s) that ensures object uniqueness. You must specify this key field name(s) using the RepositoryItemLookUpEditBase.KeyMember property.

The business object identification mechanism functions as follows. When the editor's dropdown is invoked showing the records of the lookup data source, the editor should find a match for its edit value (a business object) among the lookup records. A value(s) from the business object's key field(s) is obtained and compared with key field values of each lookup record. Once the match is found, it is highlighted in the dropdown.

When an end-user selects a certain lookup record in the dropdown, this record (the object that encapsulates this record) is assigned to the lookup editor's edit value. Ensure that the data type of lookup records is accepted by the editor's edit value.

The following properties need to be specified when binding a lookup editor to a business object:

For standalone lookup editors, these properties are available from the editor's Properties object (e.g., LookUpEdit.Properties). In-place lookup editors are presented by corresponding RepositoryItem class descendants - RepositoryItemLookUpEdit, RepositoryItemGridLookUpEdit, RepositoryItemSearchLookUpEdit and RepositoryItemTreeListLookUpEdit. Thus, the described properties are explicitly available.

Certain lookup editors may need additional customization (e.g., customize columns in the dropdown, specify the dropdown window's width and height, enable text editing, etc.). See the Lookup Editors and Main Settings topic and the LookUpEdit, GridLookUpEdit, SearchLookUpEdit and TreeListLookUpEdit class descriptions for more information.

For a standalone lookup editor, its edit value is specified by the BaseEdit.EditValue inherited property (this property is bindable). For an inplace editor, its value is provided by a cell in which the editor is embedded.

Expanded Example

Assume that you have two types of business objects (Product and Category), defined as follows:

A Data Grid is bound to a list of Product business objects.

Note that the Category.Name field in the grid's data source may not even be initialized.

If you run the example without additional customization, the grid will look like the image below.

A lookup editor will be used to display category names in the Category column and allow an end-user to edit this column by selecting categories from a dropdown list.

All available categories are stored in the following list, which will be a lookup data source for the grid's inplace lookup editor (RepositoryItemLookUpEdit).

A lookup editor is assigned to the grid control's Category column. Thus, the editor's edit value will be a Category business object.

To allow the lookup mechanism to find a match between the editor's value (a Category business object) and Category business objects in the lookup data source, a key field ("ID") is assigned to the RepositoryItemLookUpEditBase.KeyMember property.

Now, the lookup mechanism is able to find a match by comparing the ID field value of the editor's bound business object with the ID field values in the lookup data source.

Is this topic helpful?​​​​​​​