Hi
I have tried to search for this and have seen some results but with an editable column. I have a grid that has a dataset as it's data source and a decimal column that we current set the format for in the display layout in the bands columns.
I would like to know if you can set the format for a column on a row by row basis because the bands is for all the columns in the data source. Now the rows are read only so it's not like I need to edit the column.
The sample code is below but again it applies to all the columns.
For Each ocolumn As Infragistics.Win.UltraWinGrid.UltraGridColumn In grdAccounts.DisplayLayout.Bands(0).Columns
With ocolumn
Select Case .Key
Case "Current Balance"
If bShowBalances = True Then
.Format = "$#,###,##0.00"
Else
.Format = "$************"
End If
End Select
End Width
Next
I have attached a sample project here which demonstrates how to use embeddable editors to provide a different format for each row and by utilizing the cells 'Editor' property.
Let me know if you have any additional questions.
Thanks for the sample and response. I did see that sample in a previous post so I tried it with setting a format of "$*******" after 2 decimal points and that worked.
However in my production code. I load a dataset, set the grid's data source to said dataset, iterate through the bands and set the format for the column there and then I appeared to hit the row initialize and the format on the band seemed to take precedence over the format I was setting with an editor at the row initialize error.
I'm enclosing a sample application on how we work with the grid. If I comment out the setting of the format on the band's column then the code in the row initialize works.
Thanks again!
I'm not sure I follow you. Can't you just clear the Format property (call ResetFormat on the column) for those cases where you need to set the format at the row/cell level?
Ah. I did not see that method to ResetFormat on the column. So I modified the initialize row handler to this and then the sample code I had here seemed to work. It does seem redundant to call the ResetFormat on the column in the initialize row but this worked without me having to take out the setting the format in the FormatGrid column.
Private Sub grdAccounts_InitializeRow(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdAccounts.InitializeRow
Dim band As UltraGridBand = Me.grdAccounts.DisplayLayout.Bands(0)
Dim defaultEditorOwnerSettings As New DefaultEditorOwnerSettings()
Dim format As String = "$#,###,##0.00"
band.Columns("CurrentBalance").ResetFormat()
If index = 1 Then
format = "$************"
defaultEditorOwnerSettings.Format = format
Dim defaultEditorOwner As New DefaultEditorOwner(defaultEditorOwnerSettings)
Dim editorWithText As New EditorWithText(defaultEditorOwner)
e.Row.Cells("CurrentBalance").Editor = editorWithText
index += 1
End Sub
I agree that it's redundant to call ResetFormat inside of InitializeRow. I was thinking more along the lines of setting it when you prepare the grid initially for whatever view you are going to use currently.
You mentioned something about using the same grid in different "panels." I'm not sure what "panels" means exacrty in this case, but whenever you move the grid into the panel, you presumably know at that point whether the grid requires row-level formatting or not and could set 9or reset) the Format on the column at that point.
BTW... if you are concerned about efficiency, then creating a new EditorWithText inside InitializeRow is extremely inefficient. You will end up creating a huge number of these editors. You'd be better off creating two of them up front (one for each format) and then referencing them here. In which case, applying them to every row will not be a performance problem, anyway, and you could just as easily forego setting the Format on the column entirely. :)
So I get the we should declare two editors and use the same two but what about the default owner editor settings and default owner? Should two of those be instantiated and created for each editor one with the mask and one without? Or can one of those be used for both just change the format before assigning to it.
Rene
Hi Rene,
You need an owner for each editor. So what I would do is create the editor and the owner at the same time. Then all you need to do in IntiializeRow is assign the appropriate editor to the cell and you don't need to worry about the owners any more - they are already associated with the editor.