'Declaration Public Property Converter As IValueConverter
public IValueConverter Converter {get; set;}
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.
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 } }
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