Question: I'm populating a datagridview with data and one of the columns should be shown as time i.e. hh:mm:ss.

The data is extracted from the Access database and successfully populates in the datagridview. The column I want to show as time is populated in the access database as "Number". As you will see I covert it down to seconds using /86400 within the select query.

When I try to convert the column using DefaultCellStyle.Format = "hh:mm:ss tt", the entire column of data is replaced with just "hh:mm:ss tt" in each cell i.e. there are no longer numbers, its just hh:mm:ss tt in every cell.

Below is my code - can anyone advise what I am doing wrong?

```
string strProvider =
    "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = P:\\JC_StockFile\\Mitel\\Mitel.accdb";
string strSql =
    "SELECT [MidnightStartDate], [Agent Name], [LoginTime], [LogoutTime], [ShiftDuration]/86400 as ShiftDuration " +
    "FROM login_data " +
    "WHERE [MidnightStartDate] > @LeDate";

OleDbConnection con = new OleDbConnection(strProvider);
OleDbCommand cmd = new OleDbCommand(strSql, con);
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@LeDate", DateTime.Today.AddDays(-3) );
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable scores = new DataTable();
da.Fill(scores);
dataGridView1.DataSource = scores;
dataGridView1.Columns["ShiftDuration"].DefaultCellStyle.Format = "hh:mm:ss tt";

```

Answer: 
I believe this property works like other String Formats. Edit: I think actually you just have an upper case issue:

Try this:

`dataGridView1.Columns["ShiftDuration"].DefaultCellStyle.Format = "HH:mm:ss";`

Reference:
<https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx>
Microsoft suggest to use `CellFormatting` event 

```
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // If the column is the ShiftDuration column, check the
    // value.
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "ShiftDuration")
    {
        ShortFormDateFormat(e);
    }
}

private static void ShortFormDateFormat(DataGridViewCellFormattingEventArgs formatting)
{
    if (formatting.Value != null)
    {
        try
        {
            DateTime theDate = DateTime.Parse(formatting.Value.ToString());
            String dateString = theDate.toString("hh:mm:ss tt");    
            formatting.Value = dateString;
            formatting.FormattingApplied = true;
        }
        catch (FormatException)
        {
            // Set to false in case there are other handlers interested trying to
            // format this DataGridViewCellFormattingEventArgs instance.
            formatting.FormattingApplied = false;
        }
    }
}

```