Split DateTime Column into two lines

3 posts, 0 answers
  1. Zurab
    Zurab avatar
    2 posts
    Member since:
    Apr 2018

    Posted 11 Oct Link to this post

    Is it possible to split DateTime column value with FormatString as {0:MM/dd/yyyy} \Newline {0:hh:mm:ss}?
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3414 posts

    Posted 11 Oct Link to this post

    Hello, Zurab,      

    The easiest way to split the DateTime values in the grid cells is to handle the CellFormatting event and split the text as follows: 
            DateTime dt;
    
            private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
            {
                if (e.Row is GridViewDataRowInfo && e.Column is GridViewDateTimeColumn)
                {
                    dt = (DateTime)e.CellElement.Value;
                    if (dt != null)
                    {
                        e.CellElement.Text = string.Format("{0:MM/dd/yyyy}", dt) + Environment.NewLine + string.Format("{0:hh:mm:ss}", dt);
                    }
                }
            }


    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Zurab
    Zurab avatar
    2 posts
    Member since:
    Apr 2018

    Posted 15 Oct Link to this post

    It's works fine.

    Thank you.

Back to Top