FlexGrid for WinForms
Value-Mapped Lists
Show AllShow All
Hide AllHide All

The ComboList property described above ensures that cell values are selected from a list. The value selected by the user is converted into the appropriate type for the column and stored in the grid, exactly as if the user had typed the value.

In many cases, cells can assume values from well-defined lists, but you want to display a user-friendly version of the actual value. For example, if a column contains product codes, you may want to store the code but display the product name instead.

This is accomplished with the DataMap property. This property contains a reference to an IDictionary object that establishes the mapping between what is stored in the grid and what is visible to the user (the IDictionary interface is defined in the System.Collections namespace, and is implemented by the Hashtable class among others).

For example, the code below creates a data map that contains color values and their names. The colors are stored in the grid, and their names are displayed to the user:

To write code in Visual Basic

To write code in C#

Any class that implements IDictionary can be used as a DataMap. For example, Hashtable, ListDictionary, and SortedList all provide valid data maps. The difference is that when they are used in editable columns, the order of the items in the drop down list will depend on the class.

The SortedList class sorts items by key, Hashtable uses an arbitrary order, and ListDictionary keeps the order in which items were added to the list. Because of this, ListDictionary is usually the best choice for DataMaps.

Note that the keys in the data map must be of the same type as the cells being edited. For example, if a column contains short integers (Int16), then any data maps associated with the column should have short integer keys. Using regular integers (Int32) as keys would not work.

The example below shows the difference:

To write code in Visual Basic

To write code in C#

Also, if the column's DataType property is set to an enumeration, the grid will automatically build and use a data map with the names of each value in the enumeration. For example, the following code creates an enumeration containing countries. The country values are stored in the grid, and their names are displayed to the user:

To write code in Visual Basic

To write code in C#

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback