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
    Templated ListBox Items
   [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]ASP.NET Core 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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Using a Dictionary Lookup Data Source

The DevExpress Windows Forms lookup editors support easy initialization when their lookup data sources are Dictionary<TKey, TValue> objects, provided that TKey and TValue are simple data types (e.g., integer, string, etc.). This topic shows how to set up a lookup editor in this case.

Assume that you have a field of a simple data type (e.g., integer). This field values should be presented using associated display values. For instance, instead of category IDs you should display category names. One of solutions to this task is using a lookup editor whose lookup data source is a Dictionary<TKey, TValue> object.

Create a Dictionary<TKey, TValue> object that associates field values (of the TKey type) with display values (of the TValue type), and use this Dictionary as a lookup data source (assign it to the RepositoryItemLookUpEditBase.DataSource property).

For a Dictionary<TKey, TValue> lookup data source, the lookup editor automatically creates two columns ("Key" and "Value") in the dropdown. The "Key" column values match the lookup editor's bound field values. Thus, when an end-user selects a row in the dropdown, this row's Key column value is assigned to the lookup editor's edit value.

The "Value" column specifies values displayed in the editor's edit box.

Note

No additional customization of the RepositoryItemLookUpEditBase.DisplayMember, RepositoryItemLookUpEditBase.KeyMember, and RepositoryItemLookUpEditBase.ValueMember properties is required when the lookup data source is a Dictionary<TKey, TValue> object.

Note

By default, the LookUpEdit control hides the "Key" column by setting its LookUpColumnInfo.Visible property to false.

To access and customize the "Key" and "Value" columns in the LookUpEdit control (for instance, to change the "Value" column caption), use the RepositoryItemLookUpEdit.Columns collection.

Expanded Example

Show Me

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

This example shows how to set up an in-place lookup editor when its lookup data source is a Dictionary<simpleDataType, simpleDataType> object.

In the example, integer values of the CategoryID grid column are edited using an in-place LookUpEdit control (RepositoryItemLookUpEdit). The lookup data source is a Dictionary<int, string> object that associates category IDs with category names.

The following image shows the result:

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