Qazi Ahmad
Qazi Ahmad

Reputation: 1

How to set 12 hours format in a DataGridView?

enter image description here

Can anyone tell me how to change the time format in a DataGridView ?

My requirement is to have a 12 hours format with AM, PM. For example 10:23 am, 10:23 pm. I have tried this:

datagridview.column(6).DefaultCellStyle.Format = "hh:mm"

DGVDWA.Columns(6).DefaultCellStyle.Format = "hh:mm:ss tt"enter image description here but it shows an error popup (it worked in VB.NET Windows form app).

Upvotes: 0

Views: 4153

Answers (1)

user3220812
user3220812

Reputation: 197

Try adding "tt" to the end of your code to set the format:

datagridview.column(6).DefaultCellStyle.Format = "hh:mm:ss tt"

This should display the time as 10:59:01 PM. Remove the :ss if you do not want to display seconds.

More information can be found here: MSDN

Upvotes: 1

Related Questions