Matt
Matt

Reputation: 7254

DevExpress GridControl, how to make **any** columns that are of type DateTime display in a specific DateTime format?

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.

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

Answers (1)

Jcl
Jcl

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

Related Questions