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

Date formatting

5 Answers 65 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
SSirica asked on 22 Sep 2014, 07:24 PM
I have a date coming from the database in the format yyyymmdd.  I would like it to display in the drop down as mm/dd/yyyy.  I thought I could accomplish this with the FormatString, but as I'm finding out...not so much.  Anybody got any ideas how to accomplish this?

Thanks
Steve

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Sep 2014, 08:32 AM
Hi Steve,

Thank you for writing.

In order to set the format string you should cast the auto generated column to GridViewDateTimeColumn. In addition you can set the format for the cell text and the editor:
void Form1_Load(object sender, EventArgs e)
{
    
    GridViewDateTimeColumn dateColumn = radGridView1.Columns["Date"]as GridViewDateTimeColumn;
    dateColumn.Format = DateTimePickerFormat.Custom;
    dateColumn.CustomFormat = "MM/dd/yyyy";
    dateColumn.FormatString = "{0:MM/dd/yyyy}";
 
}

I hope this helps.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 25 Sep 2014, 01:47 PM
Thanks for your response, but that didn't work.  still showing up as yyyymmdd.  is there any was to call a function to do the formatting?
0
Dimitar
Telerik team
answered on 26 Sep 2014, 12:12 PM
Hi Steve,

Thank you for writing back.

I have prepared and attached a small sample to show you how to format the column. Could you please check it and let me know how it fits in your case?

I am looking forward to your reply.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 26 Sep 2014, 12:38 PM
Thanks for your reply and example.  Formatting a normal date is not the issue.  The part of the puzzle you're missing is that the date is in the format of yyyymmdd, so today would be returned from the database as 20140926.  
0
Dimitar
Telerik team
answered on 29 Sep 2014, 02:14 PM
Hi Steve,

Thank you for writing back.

If I understand correctly you are getting the date as a string from the database and you want to format it. This can be achieved by using the CellFormatting event and manually formatting the text of the cells:
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Column.Name == "StringDate"&& e.CellElement.Value!= null)
    {
        DateTime temp = DateTime.ParseExact(e.CellElement.Value.ToString(), "yyyymmdd", CultureInfo.InvariantCulture);
       e.CellElement.Text = string.Format("{0:MM/dd/yyyy}", temp);
    }
}

I hope this helps.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
MultiColumn ComboBox
Asked by
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or