DateTime values in DataGrid

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?
 
T

Tim Wilson

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?
 
C

Claes Bergefall

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top