Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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
   [Expand]Simple Editors
   [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
   [Expand]Token Edit Control
   [Expand]Breadcrumb Edit Control
   [Expand]Range Control
   [Expand]Image Slider
    Camera Control
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T377757.

How would you rate this topic?​​​​​​​