Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sort a DataGridView by Date and Time fields

Status
Not open for further replies.

ProtocolPirate

Programmer
Nov 21, 2007
104
US
When I sort a Date field I end up with the 1pm coming before 10am and 7am coming after 4pm. I've been trying to figure out how to do a custom sort, but I can figure out how to hook into a DGV to do a custom sort. Ultimately I want clicking on either the date or the time header to sort by both columns, in addition to the fact that I don't want to have to display the time in military format to get a clean sort.
 
What data type are you using to store the date and time entries? If you were using an actual datetime object it should sort properly. If you're using a string field, then you could try converting the time to 24-hour format and sort that way

im in ur stakz, overflowin ur heapz!
 
I am using a Date primitive. I don't want a military clock, these are very simple users who would be confused by that.
 
Like macleod1021 said if it is an actual date field then it should sort automatically. You might want to do a test on the value type just to make sure.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top