Version

DataFilter Property (UltraOptionSet)

If different than null, specifies custom data filter used by the editor.
Syntax
'Declaration
 
Public Property DataFilter As Infragistics.Win.IEditorDataFilter
public Infragistics.Win.IEditorDataFilter DataFilter {get; set;}
Example
This example shows one way to use data filter functionality. We enhance ColorPickerEditor by adding data filter which handles conversions between Display and Editor ("Redish" to Color.Red and other way round) and also between Editor and Owner (Color.Red to some custom object and other way round). You don't have to implement all conversions in IEditorDataFilter.Convert() method. For conversions you are implementing, you need to set the Handled flag to True. Data filter is advanced feature as you need to be familiar with the way editors work in order to implement conversions in a correct way.

Private Class ColorPickerEditorDataFilter
    Implements IEditorDataFilter

    Public Function Convert(ByVal convertArgs As Infragistics.Win.EditorDataFilterConvertArgs) As Object Implements Infragistics.Win.IEditorDataFilter.Convert
        If convertArgs.Direction = ConversionDirection.OwnerToEditor Then
            convertArgs.Handled = True
            If Not (convertArgs.Value Is Nothing) And convertArgs.Value.GetType() Is GetType(GenericObjectHolder) Then
                Return CType(convertArgs.Value, GenericObjectHolder).Obj
            Else
                convertArgs.IsValid = False
                Return Nothing
            End If
        ElseIf convertArgs.Direction = ConversionDirection.EditorToOwner Then
            convertArgs.Handled = True
            Return New GenericObjectHolder(convertArgs.Value)
        ElseIf convertArgs.Direction = ConversionDirection.EditorToDisplay Then
            convertArgs.Handled = True
            If convertArgs.Value Is Nothing Or convertArgs.Value Is DBNull.Value Then Return ""

            If convertArgs.Value.GetType() Is GetType(Color) Then
                Return CType(convertArgs.Value, Color).Name + "ish"
            Else
                convertArgs.IsValid = False
                Return Nothing
            End If
        ElseIf convertArgs.Direction = ConversionDirection.DisplayToEditor Then

            convertArgs.Handled = True

            Dim strVal As String = convertArgs.Value

            If strVal <> Nothing And strVal.EndsWith("ish") Then
                Return Color.FromName(strVal.Substring(0, strVal.Length - "ish".Length))
            Else
                convertArgs.IsValid = False
                Return Nothing
            End If
        Else
            Throw New Exception("Something is wrong.")
        End If
    End Function
End Class

Private Class GenericObjectHolder
    Public Obj As Object = Nothing

    Public Sub New(ByVal obj As Object)
        Me.Obj = obj
    End Sub
End Class

Public Sub New()
    MyBase.New()

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

    'Add any initialization after the InitializeComponent() call
    InitGrid()
End Sub

Private Sub InitGrid()
    ' create data table 
    Dim dataSet As New DataSet()
    Dim dataTable As New DataTable()

    dataSet.Tables.Add(dataTable)

    Dim dataColumn As New DataColumn("id", GetType(Integer))

    dataColumn.AutoIncrement = True
    dataTable.Columns.Add(dataColumn)

    dataTable.Columns.Add(New DataColumn("ColorPickerDF", GetType(GenericObjectHolder)))

    Me.UltraGrid1.DataSource = dataSet

    ' set data filter on editor
    Dim editor As EmbeddableEditorBase
    editor = New ColorPickerEditor()
    editor.DataFilter = New ColorPickerEditorDataFilter()
    Me.UltraGrid1.DisplayLayout.Bands(0).Columns("ColorPickerDF").Editor = editor

    ' add rows
    Dim row As DataRow
    row = dataTable.NewRow()
    row("ColorPickerDF") = New GenericObjectHolder(Color.Red)
    dataTable.Rows.Add(row)

    row = dataTable.NewRow()
    row("ColorPickerDF") = New GenericObjectHolder(Color.Green)
    dataTable.Rows.Add(row)
End Sub
private class ColorPickerEditorDataFilter : IEditorDataFilter
{
	public virtual object Convert(EditorDataFilterConvertArgs convertArgs)
	{
		if(convertArgs.Direction==ConversionDirection.OwnerToEditor)
		{
			convertArgs.Handled = true;

			if(convertArgs.Value!=null && convertArgs.Value.GetType()==typeof(GenericObjectHolder))
				return ((GenericObjectHolder)convertArgs.Value).Obj;
			else 
			{
				convertArgs.IsValid = false;
				return null;
			}
		}
		else if(convertArgs.Direction==ConversionDirection.EditorToOwner)
		{
			convertArgs.Handled = true;

			return new GenericObjectHolder(convertArgs.Value);
		}
		else if(convertArgs.Direction==ConversionDirection.EditorToDisplay)
		{
			convertArgs.Handled = true;

			if(convertArgs.Value==null || convertArgs.Value==DBNull.Value)
				return "";

			if(convertArgs.Value is Color)
				return ((Color)convertArgs.Value).Name + "ish";
			else
			{
				convertArgs.IsValid = false;
				return null;
			}
		}
		else if(convertArgs.Direction==ConversionDirection.DisplayToEditor)
		{
			convertArgs.Handled = true;

			string strVal = convertArgs.Value as string;

			if(strVal!=null && strVal.EndsWith("ish"))
				return Color.FromName( strVal.Substring(0, strVal.Length - "ish".Length) );
			else
			{
				convertArgs.IsValid = false;
				return null;
			}
		}
		else 
			throw new Exception("Something is wrong.");
	}		
}

private class GenericObjectHolder
{
	public object Obj = null;

	public GenericObjectHolder(object obj)
	{
		this.Obj = obj;
	}
}

public Form1()
{
	// Required for Windows Form Designer support
	InitializeComponent();

	// TODO: Add any constructor code after InitializeComponent call
	InitGrid();
}
		
private void InitGrid()
{
	// create data table 
	DataSet dataSet = new DataSet();
	DataTable dataTable = new DataTable();
	dataSet.Tables.Add(dataTable);

	DataColumn dataColumn = new DataColumn("id", typeof(int));
	dataColumn.AutoIncrement = true;
	dataTable.Columns.Add(dataColumn);

	dataTable.Columns.Add( new DataColumn("ColorPickerDF", typeof(GenericObjectHolder)) );

	this.ultraGrid1.DataSource = dataSet;

	// set data filter on editor
	EmbeddableEditorBase editor = new ColorPickerEditor();
	editor.DataFilter = new ColorPickerEditorDataFilter();
	this.ultraGrid1.DisplayLayout.Bands[0].Columns["ColorPickerDF"].Editor = editor;
	
	// add rows
	DataRow row;
	row = dataTable.NewRow();
	row["ColorPickerDF"] = new GenericObjectHolder(Color.Red);
	dataTable.Rows.Add(row);

	row = dataTable.NewRow();
	row["ColorPickerDF"] = new GenericObjectHolder(Color.Green);
	dataTable.Rows.Add(row);
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, 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