Jar*_*ley 7 c# sqlite datetime datagridview
我正在处理名称记录应用程序,信息存储在SQLite数据库中.数据库中的所有列都是TEXT类型,除了出生日期列,这是DATETIME.我转移到SQLite数据库的原始Access数据库允许出生日期为空,所以当我复制它时,我将所有空值设置为DateTime.MinValue.
在我的应用程序中,出生日期列的格式如下:
DataGridViewTextBoxColumn dateOfBirth = new DataGridViewTextBoxColumn();
dateOfBirth.HeaderText = "DOB";
dateOfBirth.DataPropertyName = "DateOfBirth";
dateOfBirth.Width = 75;
dateOfBirth.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dateOfBirth.DefaultCellStyle.Format = "MM/dd/yyyy";
Run Code Online (Sandbox Code Playgroud)
我的问题是没有出生日期的行,数据库有DateTime.MinValue,它在我的DataGridView中显示为01/01/0001.
我正在寻找一种方法来替换我的DataGridView中的空字符串("")01/01/0001.
private void resultsGrid_DateFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
if(resultsGrid.Columns[e.ColumnIndex].Name.Equals("DateOfBirth"))
{
if ((DateTime)(resultsGrid.CurrentRow.Cells["DateOfBirth"].Value) == DateTime.MinValue)
{
// Set cell value to ""
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道我如何用空字符串替换DataGridView中的DateTime.MinValue?谢谢!
编辑:使用DateTime转换单元格值允许我必须使用if语句,但我仍然无法找出用空字符串替换MinValues的编码.
你只需要将它转换为DateTime
if ((DateTime)(resultsGrid.CurrentRow.Cells["DateOfBirth"].Value) == DateTime.MinValue)
{
// Set cell value to ""
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9943 次 |
| 最近记录: |