Version

Converter Property (Field)

Gets/sets a converter to use to convert the value of each cell represented by this Field
Syntax
'Declaration
 
Public Property Converter As IValueConverter
public IValueConverter Converter {get; set;}
Remarks

This object is used to convert a Cell's Cell.Value from its DataType to and from the EditAsTypeResolved. The converted value can be accessed thru the cell's Cell.ConvertedValue property or via the DataRecord's DataRecord.GetCellValue and DataRecord.SetCellValue methods.

To change this Field's EditAsType set its Settings.FieldSettings.EditAsType property.

Note: The converter's Convert and ConvertBack methods are called even if the Field's DataType matches its EditAsTypeResolved.

Example
The following shows how to implement a value converter for a boolean field in code and set a field's Converter property in xaml.

Imports Infragistics.Windows.DataPresenter

Class Window1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

    End Sub

    Private Sub XamDataGrid1_InitializeRecord(ByVal sender As Object, ByVal e As Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs) Handles XamDataGrid1.InitializeRecord
        Dim dr As DataRecord

        If (e.Record.GetType() Is GetType(DataRecord)) Then
            dr = CType(e.Record, DataRecord)
            dr.Cells("VIP").Value = False
        End If
    End Sub
End Class

Public Class BoolToYesNoConverter : Implements IValueConverter

    Public Shared ReadOnly Instance As New BoolToYesNoConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert

        If (targetType Is GetType(String)) Then
            If (value Is Nothing) Then
                Return "No"
            End If

            If (value.GetType() Is GetType(Boolean)) Then
                If (CType(value, Boolean) = True) Then
                    Return "Yes"
                End If

            End If

            Return "No"
        End If


        Return value

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack

        If (targetType Is GetType(Boolean)) Then
            If (value Is Nothing) Then
                Return False
            End If

            If (value.GetType() Is GetType(String)) Then
                If (String.Compare(CType(value, String), "yes", True, culture) = 0) Then
                    Return True
                End If
            End If

            Return False
        End If

        Return value

    End Function
End Class
using Infragistics.Windows.DataPresenter;

namespace Snippet_app_1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            this.XamDataGrid1.InitializeRecord += new EventHandler<Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs>(OnInitializeRecord);
        }

        void OnInitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            DataRecord dr = e.Record as DataRecord;

            if (dr != null)
                dr.Cells["VIP"].Value = false;
            
        }
    }

    public class BoolToYesNoConverter : IValueConverter
    {
        public static BoolToYesNoConverter Instance = new BoolToYesNoConverter();

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(string) )
            {
                if (value is bool)
                {
                    if ((bool)value == true)
                        return "Yes";
                }

                return "No";
            }

            return value;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(bool))
            {
                if (value is string)
                {
                    if (string.Compare((string)value, "yes", true, culture) == 0)
                        return true;
                }

                return false;
            }
            return value;
        }

        #endregion
    }

}
<Window x:Class="Snippet_app_1.Window1"
    
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
xmlns:igDP="http://infragistics.com/DataPresenter"
    
xmlns:igEditors="http://infragistics.com/Editors"
    
xmlns:igWindows="http://infragistics.com/Windows"
    
xmlns:igThemes="http://infragistics.com/Themes"
    
xmlns:sys="clr-namespace:System;assembly=mscorlib"
    
xmlns:local="clr-namespace:Snippet_app_1"
    
Title="Window1" Height="300" Width="300">
    
<Grid>
        
<igDP:XamDataGrid BindToSampleData="True" x:Name="XamDataGrid1">
             
<igDP:XamDataGrid.FieldLayouts>
                
<igDP:FieldLayout>
                    
<igDP:FieldLayout.Fields>
                        
<igDP:UnboundField Name="VIP" Label="VIP Yes/No" 
                                           
DataType="{x:Type sys:Boolean}"
                                           
Converter="{x:Static local:BoolToYesNoConverter.Instance}">
                            
<igDP:Field.Settings>
                                
<igDP:FieldSettings EditAsType="{x:Type sys:String}"/>
                            
</igDP:Field.Settings>
                        
</igDP:UnboundField>
                    
</igDP:FieldLayout.Fields>
                
</igDP:FieldLayout>
            
</igDP:XamDataGrid.FieldLayouts>
        
</igDP:XamDataGrid>
    
</Grid>
</Window>
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also