While reading an earlier post
http://www.infragistics.com/community/forums/p/56731/345397.aspx
i downloaded the link provided by Elena Ganeva of [Infragistics]
http://www.infragistics.com/community/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.29.10.21/TimeInXamDataGrid.zip
I changed the date format in the example to dd-MMM-yyyy this way
<igDP:XamDataGrid DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="stepStartTime"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamDateTimeEditor}" EditAsType="{x:Type sys:DateTime}" AllowEdit="False"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamDateTimeEditor}"> <Setter Property="Mask" Value="dd-MMM-yyyy"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
and I get nothing in it? Is it a bug or am I missing something?
Hello Nikhil,
Thank you for your post. I have been looking into it and the sample Elena shared and I can say that it is expected not to see anything when you apply “dd-MMM-yyyy” Mask because it is not valid. Here you can see the valid Masks:
http://help.infragistics.com/Help/NetAdvantage/WPF/2010.1/CLR3.5/html/xamEditors_Masks.html
Also I can suggest you use the Format Property instead of Mask if you want to format the Date using “dd-MMM-yyyy”. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Link is broken. Shows "Server Error in '/' Application."
Frankly this is what I want
If it a plain WPF Toolkit Grid we would do
private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{ if (e.PropertyType == typeof(DateTime)) { DataGridTextColumn dataGridTextColumn = e.Column as DataGridTextColumn; if (dataGridTextColumn != null) { dataGridTextColumn.Binding.StringFormat = somemethodreturningaformat(); // This method would return some user-defined format like "dd-MMM-yyyy". Since this can vary depending on user preferences, that's why not hard coded in here or in XAML } }}
(For more read this http://stackoverflow.com/questions/848702/need-to-format-dates-in-dynamically-built-wpf-datagrid)
What this does is that when that grid is sorted based on that datecolumn it sorts values acc. to date and not as string
so 01-Jan-2012 comes before 01-Apr-2012
----------------------------------------------------------------------------------------------------------------------------------------
For Infragistics XamDataGrid we are doing
where converter is
public class DateToStringConverter : IValueConverter{ public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if (value == null || object.ReferenceEquals(value, DBNull.Value)) { return string.Empty; } else { if ((value) is DateTime || (value) is System.DateTime) { return ((DateTime)value).ToEnglishDateTimeString(); //This method would return date vale in that user-defined format like "dd-MMM-yyyy" } else { return string.Empty; }
} } catch { return string.Empty; } }
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture){ try { if (value is string) { if (!string.IsNullOrEmpty(value)) { return DateTime.Parse(value); } } } catch (Exception ex) { } return null; }}
Now in infragistics Grid when this column is sorted since its a string and not a datetime value it sorts as string so 01-Apr-2012 comes before 01-Jan-2012 (which is wrong)
I want that column to remain as datetime column but its format should come from codebehind
Is this possible. Please attach a sample app of what you will suggest.
Thanks.
Here is a working link:
http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=xamInputs_Masks.html
also in my previous post I suggest you what you should do in order to achieve your goal.
Hope this heslp you.
Hi Stefan,
Can you help me on how to use format property to set format like 'dd-MMM-yyyy' to XamDataGrid igDP:Field?
I have added style in resources like below.
<Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="dateTimeStyle">
<Setter Property="Format" Value="dd-MMM-yyyy HH:mm:ss"/>
</Style>
I'm using it like below.
<igDP:Field Name="DateReceived" Label="Date Received" Column="8">
<igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource dateTimeStyle}" />
</igDP:Field.Settings>
</igDP:Field>
It is sorting records on form load as expected. But on header click it is sorting like string.
Thanks & Regards,
PSR
Hello,
Thank you for your post. I have been looking into it and I created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.