Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement where a particular column (Date Time column in DataGridView) is in mm/dd/yyyy (any format) format.

After clicking on a button, it should open another form where it should ask for multiple formats to change (Ex: mm/dd/yyyy to dd/mm/yyyy, mm/dd/yyyy to yyyy/mm/dd, dd/mm/yyyy to mm/dd/yyyy).

After selecting particular format and clicking on submit (Button), the changes should reflect on the column (which is on Form 1).

Please help me on programming this. I would like to get help in C#.net.

Thanks in advance.
Posted

1 solution

Use the Column.DefaultCellStyle.Format[^] and also[^] property:
C#
myDGV.Columns["MyDateColumn"].DefaultCellStyle.Format = "dd/MM/yyyy";
 
Share this answer
 
Comments
Member 8010354 16-Dec-15 2:49am    
Thank you so much for reply. But i should have multiple options to change the date format irrespective of the format i have. Is it possible?

Ex: Whether i have dd/mm/yy or mm/dd/yy or yy/mm/dd,

I would like to open another form on a button click where i should have all types of formats to convert.
OriginalGriff 16-Dec-15 3:38am    
And?
What part of this is a problem?
Member 8010354 16-Dec-15 4:01am    
Actually i didn't start coding for that task as i'm completly new to C#.net.
I just fetched the data from a file and reading into datagridview where one of the column is having the date, so i want to change that format.
Is it possible for converting only that column values (Date format) in the grid?
OriginalGriff 16-Dec-15 4:08am    
That's what my solution told you how to do...
Member 8010354 16-Dec-15 4:52am    
Okay that's perfect. If i have multiple columns with Date, then what i have to do?
Ex: Sent Date, Last Modified Date, Received Date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900