DataBinding in C#: format a DateTime

Hi, today how to format a DateTime in a DataTable:

m_dtLogNotif is a DataTable
m_mfGridLogs is a DataGrid

BindingSource bsSource = new BindingSource();
m_mfGridLogs.BeginUpdate();
bsSource.DataSource = m_dtLogNotif;
m_mfGridLogs.DataSource = bsSource;
 
 DataGridViewCellStyle dgvcsStyle = m_mfGridLogs.Columns["Time"].DefaultCellStyle.Clone();
dgvcsStyle.Format = "dd/MM/yy HH:mm:ss";
m_mfGridLogs.Columns["Time"].DefaultCellStyle = dgvcsStyle;
 
m_mfGridLogs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
m_mfGridLogs.EndUpdate(true);

Leave a Reply

Your email address will not be published. Required fields are marked *