ComponentOne Xamarin Edition
Data Mapping
Controls > FlexGrid > Features > Data Mapping

Data Mapping provides auto look-up capabilities in FlexGrid. For example, you may want to display a customer name instead of his ID, or a color name instead of its RGB value. When data mapping is configured for a column, a picker is displayed when the user edits the cell.

The image given below shows a FlexGrid with Data Mapping.

The GridDataMap class has three key properties.

The code below binds a grid to a collection of customers, then assigns a GridDataMap to the grid's 'CountryId' column so that the grid displays country names instead of raw IDs.

In Code

Copy Code
grid.ItemsSource = customers;
grid.Columns["CountryId"].DataMap = new GridDataMap() 
{ ItemsSource = countries, DisplayMemberPath = "Country", SelectedValuePath = "ID" };

If you use a KeyValuePair collection as the GridDataMap ItemsSource, you should set the DisplayMemberPath to 'Value' and SelectedValuePath to 'Key'. In case you follow MVVM, you may want to define the data map binding in XAML. The markup below shows how to configure that data map in XAML on a single GridColumn.


Copy Code
<c1:GridColumn Binding="CountryId" Header="Country">
    <c1:GridDataMap ItemsSource="{Binding Countries, Source={StaticResource viewModel}}"
                      DisplayMemberPath="Name" />

The view model exposes a collection of countries with an ID and Name property. One way to instantiate your view model is as a static XAML resource like it's used in the example above. The markup below shows how to add a view model to your page's resources.

Copy Code
    <local:MyViewModel x:Key="viewModel" />