I have looked around but I can't find a solution that either works or specifically answers my question. I have a simple datagrid setup to display data from a List<T>. One of the columns is a currency value stored as a Decimal and one is a DateTime object.
The date looks ok but I want to drop the time from the end of it. The decimal is just a decimal. I want it to show comma's for every 3 digits and I only want two decimal places (it currently shows about 8 I think).
I have tried a number of approaches including setting the Coverter however while the coverter code is being called and is converting values (I checked) the column is empty whenever I use this.
It seems to me this should be a lot simpler, a simple StringFormat parameter perhaps? What am I missing here that is making this so difficult?
Here is the xaml:
<igDP:XamDataGrid x:Name="RepTakeDataGrid" DataSource="{Binding RepTakeDataSource}" Theme="Office2k7Blue" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True" AllowAddNew="False" AllowDelete="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout > <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings AllowSummaries="True" CellClickAction="SelectRecord" ExpandableFieldRecordHeaderDisplayMode="DisplayHeaderOnlyWhenExpanded" /> </igDP:FieldLayout.FieldSettings> <igDP:FieldLayout.Fields> <igDP:Field Name="Amount" Label="Take Amount ($)" Converter="{StaticResource formatConvertor}" ConverterParameter="'{0:C2}'" /> <igDP:Field Name="EntryAccount" Label="Entry Account"/> <igDP:Field Name="SplitAccount" Label="Split Account" /> <igDP:Field Name="RepNumber" Label="Rep #" /> <igDP:Field Name="RepName" Label="Rep Name" /> <igDP:Field Name="DateReceived" Label="Date" /> <igDP:Field Name="RepCodeString" Label="Rep Code" /> <igDP:Field Name="ClientName" Label="Client" /> <igDP:Field Name="PolicyNumber" Label="Policy #" /> <igDP:Field Name="EntryType" Label="Type" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Also if you notice anything else wrong with this approach please let me know.
Thanks,
Chris
Dear Chris,
In order to format the data in your xamDataGrid all you have to do is use the embeded xamEditors in its cells.
You can do that by setting their style from the xaml like this:
<igDP:Field Name="Money"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource TheStyle}" EditAsType="{x:Type sys:Decimal}" /> </igDP:Field.Settings></igDP:Field>
<igDP:Field Name="LastPayed"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource TheStyle1}" EditAsType="{x:Type sys:DateTime}" /> </igDP:Field.Settings></igDP:Field>
Of course you'll have to make your own styles setting the Mask property which Value takes a string formatting string.
<Style TargetType="{x:Type igEditors:XamCurrencyEditor}" x:Key="TheStyle"> <Setter Property="Mask" Value="{}{currency:8.2:c}" /></Style>
<Style TargetType="{x:Type igEditors:XamMaskedEditor}" x:Key="TheStyle1"> <Setter Property="Mask" Value="dd/mm/yy" /></Style>
Hope this helps.
Regards Petar.
Alright I will give that a shot, though I find this a bit confusing for two reasons:
1. This is a read-only datagrid so what would the EditorStyle have to do with read only data fields?
2. Why do you have Converter, ConverterParameter and ConverterCulture parameters on the field when they are not being used for what they should be intended for? What are they being used for then?
Sorry, I probably should have explained I am using the express edition of the xamDataGrid, which does not appear include these editors, only the text editor.
Is it just not possible to format the text with the express edition? I can understand the express edition have limitations, but this is overall a very simple datagrid display.
Since I am using A M-V-VM here I can obviously format in the viewmodel and bind to a string property instead. My main reason for not doing this is loosing the ability to use the column summaries and get sums of the decimal amounts (I am assuming it does not format strings).
The last thing I can think of would be to write something that inherits from Decimal but overrides the ToString() method, though I am not sure if that will have the intended effect.
Is there a way in XAML to define the Language to use the current system language? For example, for a .NET TextBox you would specific in the Binding information
<TextBox Text="{Binding DblValue, StringFormat={}{0:0.##}, ConverterCulture={x:Static glob:CultureInfo.CurrentCulture}"/>
Is there an equivalent for using the CurrentCulture when defining the Language property instead of a hard-coded value such as "de-DE"?
<Setter Property="Language" Value="de-DE" />
Hello Patrick,
I have been looking into this for you and have found a way for you to use the XamTextEditor as a currency editor:
<igEditors:XamTextEditor x:Name="xamTextEditor1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Background="AliceBlue">
<igEditors:XamTextEditor.Resources>
<Style TargetType="{x:Type igEditors:XamTextEditor}">
<Setter Property="ValueType" Value="{x:Type sys:Double}" />
<Setter Property="Format" Value="#,###.##" />
</Style>
</igEditors:XamTextEditor.Resources>
</igEditors:XamTextEditor>
I tested it out with this code: xamTextEditor1.Value = 23123.43;
and this is the result:
Hope this helps. Please let me know if you require any further assistance on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
How to set for field a comma value?? I just set the Culture for de-DE, but in the Fields there are only values with points -> 12.3 i need the 12,3 with a comma.
<Style TargetType="{x:Type Editors:XamTextEditor}" x:Key="TheCurrencyStyle"> <Setter Property="Format" Value="###,#.##" /> </Style>
That doesn´t work
Hi,
If you would like to formate the column from code, you can try this out, it seems to work for my application.
Style st = new Style(typeof(XamTextEditor));
Setter setter = new Setter(XamTextEditor.FormatProperty, "dd MMM yyyy hh:mm:ss");
st.Setters.Add(setter);
XamDataGrid1.Records.FieldLayout.Fields["DateFieldColumn"].Settings.EditorStyle = st;
Michael
Hello,
I am glad that the information my colleague has provided has been helpful to you. If you have any other questions feel free to address them to us and we will be happy to help.
Best Regars,
Alex.