Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
WinGrid and individual cell formatting
posted

I know there are a number of posts already on this, but I've been through them all and am going round in circles. I have a datagrid, with a numeric column and a hidden string column that contains a format I want to apply to each cell of the numeric column. I have a handler executing on the InitializeRow event of the datagrid, with the following code ...

Private Sub DataGridInitializeRowHandler _
    (ByVal sender As Object, _
      ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs)

  Dim band As UltraGridBand = DataGrid.DisplayLayout.Bands(0)
  Dim ColumnName as String = GetColumnName
  Dim Format As String = e.Row.GetCellText(band.Columns("Format"))
  Dim editor As Infragistics.Win.EmbeddableEditorBase = EditorCache.GetEditor(Format)

  e.Row.Cells(SummaryColumn.ColumnName).Editor = editor
   
End Sub

My Format variable is being successfully populated with values such as {0:$#,##0.00} and {0:##.##%}, the editor EmbeddableEditorBase object is correctly created and assigned, but the format of the objects in the grid never changes.

Any pointers as to what I'm missing or doing wrong would be very much appreciated.

Thanks
Nick

Parents Reply
  • 440
    posted in reply to [Infragistics] Boris Toromanov

    No problem Boris. If anyone else is trying to achieve this, the EditorCache class is derived from Mike Saltzman's example here. The class simply caches editor objects to remove the overhead of repeatedly creating them. The code in VB is ...

    Friend Class EditorCache
      Implements IDisposable
      Private editorsDictionary As Dictionary(Of String, Infragistics.Win.EmbeddableEditorBase)

      Public Function GetEditor(format As String) As Infragistics.Win.EmbeddableEditorBase
        ' Try to get an existing, cached editor.
        Dim editor As Infragistics.Win.EmbeddableEditorBase = Me.GetExistingEditor(format)
        If editor IsNot Nothing Then
          Return editor
        End If

        ' If we failed to find an existing editor, create a new one and
        ' cache it.
        Return Me.CreateNewEditor(format)
      End Function

      ' Try to find an exiting editor in the cache.
      Private Function GetExistingEditor(format As String) As Infragistics.Win.EmbeddableEditorBase
        ' If the editorsDictionary is null, nothing is cached, so
        ' just return null.
        If Me.editorsDictionary Is Nothing Then
          Return Nothing
        End If

        ' Try to find an editor with the specified format.
        Dim editor As Infragistics.Win.EmbeddableEditorBase
        Dim success As Boolean = Me.editorsDictionary.TryGetValue(format, editor)

        ' If we found an existing editor, return it, otherwise, return null.
        Return If(success, editor, Nothing)
      End Function

      Private Function CreateNewEditor(format As String) As Infragistics.Win.EmbeddableEditorBase
        ' Create a new DefaultEditorOwnerSettings and set the format.
        Dim settings As New DefaultEditorOwnerSettings()
        settings.Format = format

        ' Create a new DefaultEditorOwner and pass in the settings.
        Dim editorOwner As New DefaultEditorOwner(settings)

        ' Create a new editor with the owner.
        Dim editor As Infragistics.Win.EmbeddableEditorBase = New Infragistics.Win.EditorWithText(editorOwner)

        ' Cache the editor
        If Me.editorsDictionary Is Nothing Then
          Me.editorsDictionary = New Dictionary(Of String, Infragistics.Win.EmbeddableEditorBase)()
        End If

        Me.editorsDictionary.Add(format, editor)

        ' return the new editor.
        Return editor
      End Function

     

Children
No Data