Auto-complete and mapped columns are implemented with a built-in class called ColumnValueConverter. This class deals with three common binding scenarios:
Columns that can only take on a few specific values. For example, you have a "Country" column of type string and a list of country names. Users should select a country from the list, and not be allowed to enter any countries not on the list.
You can handle this scenario with two lines of code:
C# |
Copy Code
|
---|---|
var c = _flexEdit.Columns["Country"]; c.ValueConverter = new ColumnValueConverter(GetCountryNames(), true); |
The first parameter in the ColumnValueConverter constructor provides the list of valid values. The second parameter determines whether users should be allowed to enter values that are not on the list (in this example they are not).
Columns that have a few common values, but may take on other values as well. For example, you have a "Country" column of type string and want to provide a list of common country names that users can select easily. But in this case users should also be allowed to type values that are not on the list.
You can also handle this scenario with two lines of code:
C# |
Copy Code
|
---|---|
var c = _flexEdit.Columns["Country"]; c.ValueConverter = new ColumnValueConverter(GetCountryNames(), false); |
As before, the first parameter in the ColumnValueConverter constructor provides the list of valid values. The second parameter in this case determines that the list is not exclusive, so users are allowed to enter values that are not on the list.
Columns that contain keys instead of actual values. For example, the column may contain an integer that represents a country ID, but users should see and edit the corresponding country name instead. The code below shows how you can handle this scenario:
C# |
Copy Code
|
---|---|
// build key-value dictionary var dct = new Dictionary<int, string>(); foreach (var country in GetCountryNames()) { dct[dct.Count] = country; } // get column var c = _flexEdit.Columns["CountryID"]; // create and assign converter with value dictionary c.ValueConverter = new ColumnValueConverter(dct); // align column to the left c.HorizontalAlignment = HorizontalAlignment.Left; |