简体   繁体   中英

How to format a column in DataGridView with C#

I used BindingSource to connect my DataGridView with a Microsoft Access DB.

The field in the DB is a Time is a Long Time (Input Mask is 99:00 >LL;0;_)

The DataGridView shows

12/30/1899 9:56 AM

The time is correct but the DataGridView is showing the 12/30/1899

Please help!

you want to set the DefaultCellStyle.Format = "t"

you can display only the time via the properties window for your `datagridview', look for the Columns option. Then select your column that you want to change > DefaultCellStyle > Format > Date Time > time option.

or in code:

dataGridView1.Columns["yourColumnName"].DefaultCellStyle.Format = "t";

here is some info on formatting data in a datagridview

How to: Format Data in the Windows Forms DataGridView Control

DataGridView.DefaultCellStyle Property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM