[]
        
(Showing Draft Content)

C1.WPF.FlexGrid.ColumnValueConverter

ColumnValueConverter Class

Defines a list of valid entries for a column.

Inheritance
ColumnValueConverter
Namespace: C1.WPF.FlexGrid
Assembly: C1.WPF.FlexGrid.4.6.2.dll
Syntax
public class ColumnValueConverter : IEditValueConverter, IValueConverter
Remarks
<p>This class deals with three common binding scenarios:</p>
<p>1) Columns that can only take 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. The code below shows how you can handle this scenario:

<pre><code class="lang-csharp">// get column
var c = _flexEdit.Columns["Country"];

// create and assign converter with exclusive value list
c.ValueConverter = new ColumnValueConverter(GetCountryNames(), true);</code></pre>
<p>2) Columns that have a few common values, but may take 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. The code below shows how you can handle this scenario:

<pre><code class="lang-csharp">// get column
var c = _flexEdit.Columns["Country"];

// create and assign converter with non-exclusive value list
c.ValueConverter = new ColumnValueConverter(GetCountryNames(), false);</code></pre>
<p>3) 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:

<pre><code class="lang-csharp">// 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;</code></pre>

Constructors

Name Description
ColumnValueConverter()

Initializes a new instance of a ColumnValueConverter.

ColumnValueConverter(ICollection, bool)

Initializes a new instance of a ColumnValueConverter based on a simple value list.

ColumnValueConverter(IDictionary)

Initializes a new instance of a ColumnValueConverter based on a dictionary.

ColumnValueConverter(IEnumerable, string, string)

Initializes a new instance of a ColumnValueConverter based on an object collection.

Properties

Name Description
Exclusive

Gets a value that determines whether the editor should only allow values present in the Values list.

Values

Gets the collection of values that should be displayed by the editor.

Methods

Name Description
Convert(object, Type, object, CultureInfo)

Converts data values into display values.

ConvertBack(object, Type, object, CultureInfo)

Converts display values back into data values.

SetSource(ICollection, bool)

Sets the converter source to a list of values to store in the cell.

SetSource(IDictionary)

Sets the converter source to a dictionary containing keys (objects to store in the column cells) and their corresponding display values (strings to display to the user).

SetSource(IEnumerable, string, string)

Sets the converter source to a list of objects that contain the keys (values stored in the column cells) and their corresponding display values.