DateTime values in DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am populating a DataSet using SqlAdapter and then displaying it in a DataGrid. Some of the values in the DataSet are DateTime. It seems by default they are displaying as dd/mm/yyyy and I want to also display the time. I have played around with the DataGridTableStyle and the DataGridTextBoxColumn but nothing seems to take affect. Is there a good resource that outlines how to use these classes or is their an easier way to go about things?
 
One way to do this is to create a custom DataGridColumnStyle that utilizes
the DateTimePicker. See the example in the MSDN docs.
http://msdn.microsoft.com/library/d...windowsformsdatagridcolumnstyleclasstopic.asp

This might also be helpful.
http://www.i-syn.gmxhome.de/devcom/colstyles/intro.htm

--
Tim Wilson
..Net Compact Framework MVP

Dan S said:
I am populating a DataSet using SqlAdapter and then displaying it in a
DataGrid. Some of the values in the DataSet are DateTime. It seems by
default they are displaying as dd/mm/yyyy and I want to also display the
time. I have played around with the DataGridTableStyle and the
DataGridTextBoxColumn but nothing seems to take affect. Is there a good
resource that outlines how to use these classes or is their an easier way to
go about things?
 
Set the Format property of the corresponding
DataGridTextBoxColumn to the format you want (e.g. "g").
See the docs for the DateTimeFormatInfo class for
valid values.

Note that the DataType property of the underlying
DataColumn must be set to the DateTime type (but
is sounds like it already is)

/claes

Dan S said:
I am populating a DataSet using SqlAdapter and then displaying it in a
DataGrid. Some of the values in the DataSet are DateTime. It seems by
default they are displaying as dd/mm/yyyy and I want to also display the
time. I have played around with the DataGridTableStyle and the
DataGridTextBoxColumn but nothing seems to take affect. Is there a good
resource that outlines how to use these classes or is their an easier way to
go about things?
 
Back
Top