Solved

Format Date Column in Winform Datagrid

Posted on 2004-09-14
8
301 Views
Last Modified: 2010-04-23
How do you format a Date Column in a windows form.
0
Comment
Question by:XgenX
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 12059516
If you go in the collection editor in the properties of the grid...there is a format property for each column that you can set...and you can use something such as

dd-MMM-yyyy to give 11-Jul-2004 for example...
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 12060996
0
 

Author Comment

by:XgenX
ID: 12146793
Ok, regarding natloz's comment, I go to the DataGrid properties and I don't see something called collection editor but I see a TableStyles property with a Collection value in the Data section of the properties (forgive me but I am still at the tard level of understanding in the .Net IDE). I assume this is what you are talking about. I go into this and there is a DataGridTableStyle2 in the members list. I go into this and go to the GridColumnStyles property collection. In there I find DataGridTextBoxColumn1 and DataGridTextBoxColumn2 Members. Each of these have dd-MMM-yyyy in the format property and are mapped to the correct field in the mapping name property. When I run it I just get 9/24/2004. There is a property in the Windows Form Designer generated code called FormatInfo that is not in the Collection Editor and that is set to Nothing. So, what am I doing wrong? BTW, I have tried various other formats such as G and mm-dd-yy-hh-mm-ss with absolutely no change. Thanks for the help.
0
 
LVL 7

Expert Comment

by:natloz
ID: 12146844
Check to see if there is a mapping name for the TableStyles collection editor...it should be mapped to the table in the dataset...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:XgenX
ID: 12147852
Er, ok. It wasn't. So I made the single change of hand-typeing the name of the view (it's a view, by the way, not a table) and now the only thing that shows up are the two formatted fields. None of the other fields show up. Hmmm...
0
 
LVL 7

Accepted Solution

by:
natloz earned 250 total points
ID: 12147884
You have to add a GridColumnStyle for each column you wish to display in your grid...
Basically if you define a Custom Collection Style for TableStyle/Column style...then you are overriding the autogenerated style that comes with a basic grid. So...you need to add a column for each column you wish to display in your grid, I do all my grids this way because I like to format the Widths of the grid columns based on the type of info etc...plus I like to create custom headers for each column etc...does this make sense...

So because you are now defining a mapping for the custom TableStyles...it is now going to use the custom collection.
0
 
LVL 7

Expert Comment

by:natloz
ID: 12147899
I also like to add primary keys to my grid and give the Custom column a width of 0 so if I want to capture a click event in the grid I can get the primary key without the user needing to see it...
0
 

Author Comment

by:XgenX
ID: 12148402
This seems to answer everything I was misunderstanding. Thank you so much for the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now