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.

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.