バージョン

DataFilter プロパティ (UltraOptionSet)

null以外の場合は、エディターで使用されるカスタムデータフィルターを示します。
シンタックス
'宣言
 
Public Property DataFilter As Infragistics.Win.IEditorDataFilter
public Infragistics.Win.IEditorDataFilter DataFilter {get; set;}
使用例
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);
}
参照