【问题标题】:How to format a column in DataGridView with C#如何使用 C# 格式化 DataGridView 中的列
【发布时间】:2012-04-17 10:36:57
【问题描述】:

我使用 BindingSource 将我的 DataGridView 与 Microsoft Access DB 连接起来。

DB 中的字段是 Time is a Long Time (Input Mask is 99:00 >LL;0;_)

DataGridView 显示

1899 年 12 月 30 日上午 9:56

时间正确,但 DataGridView 显示的是 12/30/1899

请帮忙!

【问题讨论】:

  • 这是一个 WinForm 应用程序,而不是一个 ASP 页面

标签: c# binding datagridview bindingsource


【解决方案1】:

你想设置DefaultCellStyle.Format = "t"

您只能通过“datagridview”的属性窗口显示时间,请寻找“列”选项。然后选择您要更改的列 > DefaultCellStyle > 格式 > 日期时间 > 时间选项。

或在代码中:

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

这里有一些关于在 datagridview 中格式化数据的信息

How to: Format Data in the Windows Forms DataGridView Control

DataGridView.DefaultCellStyle Property

【讨论】:

  • t 是仅用于时间的格式,我已添加代码来格式化列。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多