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

GridViewDateTimeColumn - FormatString ="dd-MM-yyyy HH:mm"

3 Answers 405 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mSchmidt
Top achievements
Rank 1
mSchmidt asked on 16 Sep 2008, 03:41 PM

I would like my dates to be formatted like this
dd-MM-yyyy HH:mm
which should result in
10-08-2008 15:30


However viewing data is currently formatted like this
10-09-2008 15:30:00
and when editing the values it is:
17. september 2008


I would like both formats to use this format string
dd-MM-yyyy HH:mm
And as i read it i should only set the FormatString property and this should result in both the edit and view format to be set correctly.

Below i attached my code:

puljeRounds.MasterGridViewTemplate.Columns.Add(new GridViewDateTimeColumn("Dato", "round_date") {  FormatString = "{0:dd-MM-yyyy HH:mm}" }); 

3 Answers, 1 is accepted

Sort by
0
Pawz
Top achievements
Rank 1
answered on 17 Sep 2008, 02:28 AM
You actually have to set the format on the columns *after* the grid has been bound to the datasource.

I've been banging my head on that one too. For some reason the grid drops all your formatting, requiring a manual format after databinding.

I'm not 100% sure if setting the format on the cell will handle the datetime editor as well. Anyways, I just bind and then call a custom 'ApplyFormatting' function which basically just does this:

uiJobGrid.Columns["DateManufacturePlanned"].FormatString = "{0:ddd, dd MMM}";
0
mSchmidt
Top achievements
Rank 1
answered on 17 Sep 2008, 06:27 AM
Jep it worked for the view format of the column. Thanks

However the DateTime Editor is still in the original format does anyone else know how to change this ?
0
Boyko Markov
Telerik team
answered on 19 Sep 2008, 02:44 PM
Hi guys,

I hope the sample code below will help. It's purpose is to change the formatting in the grid's DateTimeEditor:

1. Subscribe to the CellBeginEdit event

this.radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit); 

       
2. In the EventHandler change the format string of the editor.

        void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        { 
            if (this.radGridView1.ActiveEditor != null && 
                this.radGridView1.ActiveEditor.GetType() == typeof(RadDateTimeEditor)) 
            { 
                (this.radGridView1.ActiveEditor as RadDateTimePickerElement).Format = DateTimePickerFormat.Custom; 
                (this.radGridView1.ActiveEditor as RadDateTimePickerElement).CustomFormat = "dd/MM/yyyy"
 
            } 
        } 


I will be happy to answer all the questions you have about this editor.

Regards,
Boyko Markov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
mSchmidt
Top achievements
Rank 1
Answers by
Pawz
Top achievements
Rank 1
mSchmidt
Top achievements
Rank 1
Boyko Markov
Telerik team
Share this question
or