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

4 posts, 0 answers
  1. mSchmidt
    mSchmidt avatar
    47 posts
    Member since:
    Aug 2007

    Posted 16 Sep 2008 Link to this post

    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}" }); 
  2. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 16 Sep 2008 Link to this post

    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}";
  3. mSchmidt
    mSchmidt avatar
    47 posts
    Member since:
    Aug 2007

    Posted 17 Sep 2008 Link to this post

    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 ?
  4. Boyko Markov
    Boyko Markov avatar
    610 posts

    Posted 19 Sep 2008 Link to this post

    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.

    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top