I have a datatable populated with a nullable year column of datatype int. In addition, every time the year changes, I have added a blank row.
DataTable table = new DataTable();
table.Columns.Add("Year", typeof(int));
table.Columns["Year"].AllowDBNull = true;
Example of table contents:
2005
2005
DBNull.Value
2006
DBNull.Value
2007
On a row by row basis and only being able to look at the current row and the next row, how would I sort this so that the DBNull.Value rows still separate the difference in years?
Thanks!
I don’t like this sort of design in general, but here is how you could do it.
Add another column of type double, which will be hidden in the display, and call it “SortYear”. For the rows with years in them, put the year in this hidden column. For the null rows put the previous year plus 0.5. Then sort by SortYear, then by whatever column you really want to sort by other than year.