Hi
Is there a cell level property using which i can apply formats to a value for a particular cell?
I have grid(dynamic grid using ultradatasource) such that there are predefined formats(e.g. percentage,currency etc) to be applied to values for some cells within a column.
In the forums i can find ways to apply format for a complete column but that is not useful in my case.
Normal 0 false false false EN-US X-NONE X-NONE
TYPE
VALUE
a
<dollar>
b
<percentage>
I did as you suggested but it seems to only work sometimes.
It is strange one time is will format $ and % then next time there will be no format at all.
Do you have any suggestions to what to look for?
Private Sub UltraGrid1_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles UltraGrid1.InitializeRow
If bPercent then
Dim defaultEditorOwnerSettings As New DefaultEditorOwnerSettings()
defaultEditorOwnerSettings.Format = "P"
Dim defaultEditorOwner As New DefaultEditorOwner(defaultEditorOwnerSettings)
Dim editorWithText As New EditorWithText(defaultEditorOwner)
e.Row.Cells("Duty").Editor = editorWithText
Else
defaultEditorOwnerSettings.Format = "C"
End If
End Sub
Thanks
My issue is a little different. I have a numeric field and in older records I want to format it as a $ value if it is a newer row format it as %. This will be based off a date filed in the same row.
Hello webd,
The code you could use for this(should be in Form1.vb's WinGrid InitializeRow event) is:
Dim numberOfDecimalPlaces As Integer = CInt(e.Row.Cells("NumberOfDecimalPlaces").Value) Dim format As String = "#.#" If numberOfDecimalPlaces > 1 Then format += New String("0"C, numberOfDecimalPlaces - 1) End If
Dim defaultEditorOwnerSettings As New DefaultEditorOwnerSettings() defaultEditorOwnerSettings.Format = format Dim defaultEditorOwner As New DefaultEditorOwner(defaultEditorOwnerSettings) Dim editorWithText As New EditorWithText(defaultEditorOwner) e.Row.Cells("Value").Editor = editorWithText
Please do not hesitate to contact me if you need any additional assistance.
Can you give this FormatByCell.zip example in VB .net
Thanks.
The attached sample demonsrates how to apply a different format for each cell in a column without assigning a different editor to each cell (that approach is inefficient because if you have lots of cells you will be creating lots of editors). In this example, a column which contains currency values is assigned a custom EmbeddableEditorOwnerBase implementation which overrides the GetFormatInfo method; this is the method the cells use when obtaining the formatting information from the grid.