While reading an earlier post
http://es.infragistics.com/community/forums/p/56731/345397.aspx
i downloaded the link provided by Elena Ganeva of [Infragistics]
http://es.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?
Hi Stefan,
Thank you for looking into this issue.
Sorry for late reply.
Nothing worked for me so I have used sort comparer which is working as expected.
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.
Looking forward for your reply.
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.
Hello Nikhil,
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.
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.