I am working on a name recording 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 DATETIME. The original Access database that I migrated to the SQLite database was nullable for the date of birth, so when I copied it, I set all the null values ββto DateTime.MinValue.
In my application, the date of birth column is formatted as follows:
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 in rows where there is no date of birth, the database has DateTime.MinValue, which appears in my DataGridView as 01/01/0001.
I am looking for a way to replace 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 "" } } }
Does anyone have an idea how I can replace DateTime.MinValue in my DataGridView with an empty row? Thanks!
Edit: returning a DateTime cell value allows the if statement to work, which I should work on, but I'm still not able to calculate the encoding to replace MinValues ββwith an empty string.
c # datetime sqlite datagridview
Jared harley
source share