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.
ThanksNick
OK, solved this myself if anyone esle comes across a similar issue. Elsewhere in my code I wassetting the column format property. If I removed this line it works.
DataGrid.DisplayLayout.Bands(0).Columns(ColumnName).Format = sFormat
One other small point, the format string shouldn't include the type specification. Needed to change mine to be $#,##0.00 and ##.##%
Hello DataPA,
Thank you for your feedback and for sharing this with our community.
Please do not hesitate to ask if something comes up.
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