Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Show date as DD/MM/YYYY in DataGridTextBoxColumn

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jtoulier - 21 Feb 2006 00:45 GMT
Hello all,

We have a DataSet bound to a DataGrid, this DataSet has a datetime
column, coming from SQL Server.

We want to show this field on the DataGrid always as "DD/MM/YYYY",
ignoring user's regional configuration.

For example if the user has the date regional configuration as
"DD*MM*YYYY" (with stars), the DataGridTextBoxColumn shows the date as
"DD*MM*YYYY" even if our code is:

DataGridTextBoxColumn oTextBoxNatural = new DataGridTextBoxColumn();
oTextBoxNatural.MappingName = "datetime_field";
oTextBoxNatural.HeaderText = "Show date as DD/MM/YYYY";
oTextBox.Format = "dd/MM/yyyy";
oTextBoxNatural.Width = 100;
dty.GridColumnStyles.Add(oTextBoxNatural);

How can we show the date always as "DD/MM/YYYY"? We do not want to
depend on user's regional configuration since in our environment each
user configurates this as they want.

Thanks a lot.

Joseph Toulier
Claes Bergefall - 21 Feb 2006 19:29 GMT
I would double check to make sure that the DataColumn.DataType property is
set to DateTime for that column.
If it isn't, the grid doesn't know how to apply that format string

  /claes

> Hello all,
>
[quoted text clipped - 22 lines]
>
> Joseph Toulier
Bart Mermuys - 22 Feb 2006 13:40 GMT
Hi,

> Hello all,
>
[quoted text clipped - 11 lines]
> oTextBoxNatural.MappingName = "datetime_field";
> oTextBoxNatural.HeaderText = "Show date as DD/MM/YYYY";

Assign a culture to FormatInfo that uses a "/" as seperator, like the
invariant culture:

oTextBoxNatural.FormatInfo = CultureInfo.InvariantCulture;

> oTextBoxNatural.Format = "dd/MM/yyyy";
> oTextBoxNatural.Width = 100;
> dty.GridColumnStyles.Add(oTextBoxNatural);

HTH,
Greetings

> How can we show the date always as "DD/MM/YYYY"? We do not want to
> depend on user's regional configuration since in our environment each
[quoted text clipped - 3 lines]
>
> Joseph Toulier
Abhishek - 23 Feb 2006 09:45 GMT
Hi Joseph,
The format of date to be displayed can be controlled by the ToString
function for the DateTime object used by passing a format string.
E.g., when you retrieve the date from the database in a DateTime
object, say DT, then you can display it as DT.ToString("dd/MM/yyyy") in
your case. This string can have all the date time combinations as
variants. Take care of the case of the letters, especially MM (mm would
mean minutes). The date time string so obtained can be used at all
required places.

I hope this meets your requirement.

Abhishek

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.