Reputation: 7254
I databind my GridControl ItemsSource
to a collection of type List<Foo>
where Foo
contains the DateTime
property TimeStamp
. I would like to make sure that when TimeStamp
is rendered on the GridControl
that it shows in "dd-MM-yyyy HH:mm:ss.fff" format.
How can I specify that particular column given I know the column name and set the format?
What can I do to have any column that is of type DateTime
rendered in a specific format (such as "dd-MM-yyyy HH:mm:ss.fff")?
Regarding my first question I have the following, but it does not seem to work:
<dxdo:LayoutPanel Caption="Sample Data" ItemHeight="2*">
<dxg:GridControl ItemsSource="{Binding SampleData}" AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True">
<dxg:GridControl.View>
<dxg:TableView AllowEditing="False" AutoWidth="True" BestFitArea="All" AllowBestFit="True" ShowGroupPanel="True" ShowSearchPanelMode="Always"/>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="TimeStamp">
<dxe:TextEditSettings DisplayFormat="dd-MM-yyyy HH:mm:ss.fff"/>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
</dxdo:LayoutPanel>
Upvotes: 1
Views: 2179
Reputation: 28272
About the first question, you need to use DateEditSettings
, not TextEditSettings
like:
<dxe:DateEditSettings DisplayFormat="dd-MM-yyyy HH:mm:ss.fff"/>
As for the second question, you can loop through all columns and set the format... something like (untested):
foreach (var column in MyGridControl.Columns)
{
if (column.FieldType == typeof(DateTime))
{
column.ActualEditSettings.DisplayFormat = "dd-MM-yyyy HH:mm:ss.fff";
}
}
Upvotes: 2