[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
   [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
    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)

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.


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.


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

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:

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