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