Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Format Date Column in Winform Datagrid

Posted on 2004-09-14
8
319 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 70

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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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