Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I format a date column in a DataGrid?

If you have added a table style to your DataGrid (so individual column styles have been generated), then you can use code such as this to set the Format property of the particular column style.

[C#]

// add format column 3 columnstyle where column 3 holds a date
DataGridTextBoxColumn dgtbc =
  dataGrid1.TableStyles[ 0 ].GridColumnStyles[ 3 ] as DataGridTextBoxColumn;

if ( dgtbc != null )
  dgtbc.Format = "g"; // or "u" or whatever format you want to see

Contributed from George Shepherd's Windows Forms FAQ



Page view counter