setting datetime format in codebehind

1 posts, 0 answers
  1. Kevin
    Kevin avatar
    12 posts
    Member since:
    Oct 2013

    Posted 10 Dec 2013 Link to this post

    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?
Back to Top