I am working on a name record application and the information is stored in a SQLite database. All columns in the database are TEXT types, except for the date of birth column, which is a DATETIME. The original Access database that I transferred to the SQLite database allowed nulls for the date of birth, so when I copied it over, I set all nulls to DateTime.MinValue.
In my application, the date of birth column is formatted like so:
DataGridViewTextBoxColumn dateOfBirth = new DataGridViewTextBoxColumn(); dateOfBirth.HeaderText = 'DOB'; dateOfBirth.DataPropertyName = 'DateOfBirth'; dateOfBirth.Width = 75; dateOfBirth.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dateOfBirth.DefaultCellStyle.Format = 'MM/dd/yyyy';
My problem is that rows where there is not a date of birth, the database has DateTime.MinValue, which displays in my DataGridView as 01/01/0001.
I am looking for a way to replace the 01/01/0001 with an empty string (”) in my DataGridView.
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 '' } } }
Anyone have an idea how I can replace a DateTime.MinValue in my DataGridView with an empty string? Thanks!
Edit: Casting the cell value with DateTime allows the if statement I have to work, but I am still not able to figure out the coding to replace the MinValues with a blank string.
You just need to cast it to DateTime