Reputation: 75
So I have a data grid view that is named dtgQue here is the Properties of my Column.
'Setting the Properties for the Due Date
QueDueDate.Name = "DueDate"
QueDueDate.ValueType = GetType(Date)
QueDueDate.HeaderText = "Due Date"
QueDueDate.CellTemplate = New DataGridViewTextBoxCell
then after I do add a bunch of rows to that column I then do a
dtgQue.Sort(dtgQue.Columns(3), System.ComponentModel.ListSortDirection.Descending)
But is is not sorting it 100% correct for example here is a set of dates in order of how it sorts. 9/8/2014, 9/2/2014/, 9/15/2014, 10/1/2014 as you see for some reason its putting 9/2 after 9/8 which is not right.
Upvotes: 0
Views: 62
Reputation: 11233
My guess is that you should either use:
QueDueDate.ValueType = GetType(string)
QueDueDate.CellTemplate = New DataGridViewTextBoxCell
Write custom sorting function where each time DataGridViewTextBoxCell.Value
will be parsed from String
datatype to Date
data type and then use it for comparison.
Or:
QueDueDate.ValueType = GetType(Date)
QueDueDate.CellTemplate = New CalendarCell
Have a look at CalendarCell here.
If the data is of an appropriate type then it is expected to work/sort correctly.
Hope it helps!
Upvotes: 1