The following code creates a datatable which is then used as the datasource for a datagridview.
public void PopulateTimesheet()
{
DataTable dT = new DataTable();
dT.Columns.Add("Case No", typeof(string));
dT.Columns.Add("Charge Code", typeof(string));
dT.Columns.Add("Start Time", typeof(DateTime));
dT.Columns.Add("End Time", typeof(DateTime));
dT.Columns.Add("Units", typeof(int));
dataTimeSheet.DataSource = dT;
}
However the two datetime fields obviously display the whole date & time i.e. 18/01/2012 08:23 and I just want to show the time 08:23 (preferrably in 24 hour mode). I can’t however find a way to do this. Also is there a way to add a mask of the same format to ensure users input times in the correct format.
Thanking everyone in anticipation of their assistance.
Please see this MSDN topic that tells you exactly what to do: http://msdn.microsoft.com/en-us/library/f9x2790s.aspx
Assuming your DataGridView is called dataGridView1.
As for the input mask – some more googling tells me that you have to create your own cell type for that. I found this codeproject article detailing one ready-rolled solution: http://www.codeproject.com/KB/grid/DataGridViewMaskedText.aspx.