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 Data Binding / September 2006

Tip: Looking for answers? Try searching our database.

Displaying DateTime columns in DataGridView in custom format?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pedestrian - 06 Sep 2006 12:58 GMT
I create a WinForm app with some DataGridView controls using VB2005.
I have a dataTable(dt1) contains, among other, some date columns.
However, due to locally we represent date as dd/MM/yyyy format,
I have written an additional function to create yet another
dataTable (dt2) to replace the those date columns with string columns
of dd/MM/yyyy. I then set DGV dataSource to this second table (dt2).

If I were to create addition dataTables for every datatables that contain
DateTime column(s), this will cause my program consume many extra resources.

Is there any other alternative to show the date columns in DGV in custom
format (dd/MM/yyyy) without recreating an extra datatable? I would
like to retain the date columns in dataTable for other purposes.

Thanks for your reply.
Bart Mermuys - 17 Sep 2006 20:10 GMT
Hi,

>I create a WinForm app with some DataGridView controls using VB2005.
> I have a dataTable(dt1) contains, among other, some date columns.
[quoted text clipped - 9 lines]
> Is there any other alternative to show the date columns in DGV in custom
> format (dd/MM/yyyy) without recreating an extra datatable? I would

Have a look at the DataGridView column editor, see
DefaultCellStyle->Format->Custom.  If the DGV can't auto parse your format
(haven't tried) then you'll have to handle DGV.CellParsing event and do the
parsing yourself.  If your column is readonly then you don't have to care
about parsing...

---
HTH,
Greetings

> like to retain the date columns in dataTable for other purposes.
>
> Thanks for your reply.
pedestrian - 18 Sep 2006 03:59 GMT
Hi, Bart. I tried the CellParsing as you mentioned
(using example from MSDN). I don't get the expected result
perhaps I program it wrongly.

However, It then hinted me to try the CellFormatting
exp. from MSDN and I got the issue solved!   :)
Thanks for you assitance.

Signature

Regards,
Pedestrian, Penang.


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.