This is a migrated thread and some comments may be shown as answers.

setting datetime format in codebehind

0 Answers 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 10 Dec 2013, 04:22 PM
Hi, I am using the radgridview to display some dates on certain columns.  The gridview auto-generates columns, so setting the style in the xaml is not possible (from what i understand).  I want it to only display the date (no hours, minutes, etc).

I tried 2 ways:

private void dataGrid1_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
    if (e.ItemPropertyInfo.PropertyType == typeof(System.DateTime))
    {
        if (e.Column.Header == "TRADE_DATE")
            (e.Column as Telerik.Windows.Controls.GridViewColumn).CellStyle = "MM/DD/YYYY" // what do i put here? 
                //do i have to create a style in the xaml?  but it seems I cannot create a datetime format style for the cell, only the datacolumn ...

    }
}

after searching the forums I also found:
( ( GridViewDataColumn )this.radGridView.Columns[ "OrderDate" ] ).DataFormatString = "{0:dd, MMM, yyyy}";


but it seems it cannot find the GridViewDataColumn type - what is the correct syntax?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Kevin
Top achievements
Rank 1
Share this question
or