Click here to Skip to main content
11,632,011 members (69,965 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i am using datagrid view in winform, and i am using the smalldatetime as datatype, but it is accepting the date as mm/dd/yyyy HH:MM:SS AM
how to save that in
dd/mm/yyyy HH:MM:SS AM format
Posted 17-Dec-12 20:38pm
sariqkhan1.4K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check this similar thread
Date value in datagridview[^]
  Permalink  
Comments
sariqkhan at 18-Dec-12 2:51am
   
the second ans
Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.InvariantCulture;
dataGridView1.Columns("time7").DefaultCellStyle.Format =
"dd/MM/yyyy hh:mm tt";
it is showing the error at column
Non-invocable member 'System.Windows.Forms.DataGridView.Columns' cannot be used like a method
__TR__ at 18-Dec-12 3:16am
   
Try this
dataGridView1.DataSource = ds;
dataGridView1.Columns["your Column Index"].DefaultCellStyle.Format = "dd/MM/yyyy hh:mm:ss";
dataGridView1.DataBind();
sariqkhan at 18-Dec-12 3:54am
   
sir i am using c sharp what code you are providing?
two errors are there
The name 'ds' does not exist in the current context
'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?
__TR__ at 18-Dec-12 4:01am
   
Ds is your datasource. Change it to point to your data-source variable.
You can get rid of the dataGridView1.DataBind() line as this is a winform. did not notice that.
sariqkhan at 18-Dec-12 4:23am
   
i dont know about datasource variable what is that?
__TR__ at 18-Dec-12 4:27am
   
How are you getting data into the data girdview ? through dataset, datatable. that will be the datasource.
sariqkhan at 18-Dec-12 4:50am
   
dataGridView1.DataSource = database1DataSet11;
dataGridView1.Columns[4].DefaultCellStyle.Format = "dd/MM/yyyy hh:mm:ss";
i have added this but not working
__TR__ at 18-Dec-12 5:37am
   
What's the error message?
sariqkhan at 18-Dec-12 5:45am
   
i got you solution but the problem is it only shows that format it i want to edit the column then i cant do, have you tried that?
__TR__ at 18-Dec-12 5:57am
   
No. I would suggest you post a new question with whatever you have done so far and the problem you are facing in edit mode.
sariqkhan at 18-Dec-12 2:58am
   
in designer of datagrid view how to make the format of smalldatetime as dd/mm/yyyy hh:mm:ss AM in designer there is no option here in the default cell type, all the two option is not working in my case

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

  Print Answers RSS
0 OriginalGriff 8,393
1 Sergey Alexandrovich Kryukov 8,044
2 Mika Wendelius 6,260
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 1,970


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100