What's the simplest way to format numbers appearing in a particular column of the grid. For example if I want the number 1234.56 to appear as 1,234.5600.
Hello,
You can set the masks and format properties of the editor (EditorStyle property of the field).
You can see the default masks here. This will display this when the editor is in edit mode. If you want when the editor is not in edit mode, you can set the Format property using standard .net formatting.
Thanks for the reply.
I'm interested in the format when not in edit mode at this stage. When you say set the Format property, set the Format property of what exactly ?
The format is the standart .net formatting strings.
You can see more information about them here in the MSDN: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
For this, you can use something like this:
Format="000,000,000.0000"
or this
Format="###,###,###.000"
where 0 is a required placeholder and # is not.
Sorry for being a pain, but which object has a Format property that I should be setting. For example do I set the Format property of a Field object (presumably not because this doesn't appear to have a Format property). If not a Field object then what exactly. Thanks.
The answer is In my initial post, but I should have probably noted this better. The Field exposes EditorStyle property. So you can create a style for the value editor and set it to that. The editor itself exposes the Format property and you can set the formatting string there.
The Field doesn't expose the EditorStyle property. Field exposes the Settings property and this exposes the EditorStyle property. EditorStyle property doesn't expose a Format property so none of this really helps.
I'm still not sure what object I need to create/reference that has a Format property. Any chance of providing some sample code ? For example how do I set the format of a column containing Doubles only (Type = GetType(Double)) to be "##0.00".
My mistake on the Field's Settings:
<igDP:Field Name="nDouble">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamNumericEditor}">
<Setter Property="Format" Value="##0.00"/>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
That's what I was looking for. Thanks.
Dim style As New Style(GetType(XamNumericEditor))
Dim s As New Setter(XamNumericEditor.FormatProperty, "##0.00")
style.Setters.Add(s)
This is the code in VB for the style. You can apply it to the specific Field's Settings.
Let's say that a particular column is displaying numeric data with 2 decimals places and you want to allow the user to increase the number of decimal places displayed in this column by clicking an appropriate toolbar button. How could this be done ?
You do not have to create the whole style in code behind. You can set the x:Key attribute of the style and get it as a resource by this key from where you have defined it.
Hopefully we're nearly there.
Could you provide some sample code (VB or C#) as opposed to sample XAML. I assume this will begin as shown below. If you could fill in the blanks that would be great. Thanks.
Dim Field As Field = Grid.LayoutSettings.Item(0).Fields("Field1")
Field.Settings.EditorStyle....