Click here to Skip to main content
12,701,051 members (30,595 online)
Rate this:
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 21:38pm

1 solution

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

Solution 1

Check this similar thread
Date value in datagridview[^]
sariqkhan 18-Dec-12 2:51am
the second ans
Thread.CurrentThread.CurrentCulture =
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__ 18-Dec-12 3:16am
Try this
dataGridView1.DataSource = ds;
dataGridView1.Columns["your Column Index"].DefaultCellStyle.Format = "dd/MM/yyyy hh:mm:ss";
sariqkhan 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__ 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 18-Dec-12 4:23am
i dont know about datasource variable what is that?
__TR__ 18-Dec-12 4:27am
How are you getting data into the data girdview ? through dataset, datatable. that will be the datasource.
sariqkhan 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__ 18-Dec-12 5:37am
What's the error message?
sariqkhan 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__ 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
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