Wednesday, June 29, 2011

Formating date and time in a datagridview in C#

Hi,
The easiest way to format a datetime variable on a datagridview is to set the cell style. For example:



dataGridView1.Columns[1].DefaultCellStyle.Format = "dd'/'MM'/'yyyy hh:mm:ss tt";


If we only need the time, this is my case, we will write


dataGridView1.Columns[1].HeaderText = "Time";
dataGridView1.Columns[1].DefaultCellStyle.Format = "hh:mm";


Hope help!

No comments:

Post a Comment