.net DataGridView排序问题
因此,我有一个名为dtgQue的数据网格视图,这里是我的列的属性.net DataGridView排序问题,.net,vb.net,sorting,datagridview,.net,Vb.net,Sorting,Datagridview,因此,我有一个名为dtgQue的数据网格视图,这里是我的列的属性 'Setting the Properties for the Due Date QueDueDate.Name = "DueDate" QueDueDate.ValueType = GetType(Date) QueDueDate.HeaderText = "Due Date" QueDueDate.CellTemplate = New DataGridViewTextBoxCell 然后,在我向该列添加一堆行之后,我再执行一
'Setting the Properties for the Due Date
QueDueDate.Name = "DueDate"
QueDueDate.ValueType = GetType(Date)
QueDueDate.HeaderText = "Due Date"
QueDueDate.CellTemplate = New DataGridViewTextBoxCell
然后,在我向该列添加一堆行之后,我再执行一个
dtgQue.Sort(dtgQue.Columns(3), System.ComponentModel.ListSortDirection.Descending)
但它的排序不是100%正确的,例如,这里有一组日期,按照排序的顺序排列。2014年9月8日、2014年9月2日、2014年9月15日、2014年10月1日,正如你所看到的,出于某种原因,将9/2放在9/8之后是不正确的 我猜您应该使用:
QueDueDate.ValueType = GetType(string)
QueDueDate.CellTemplate = New DataGridViewTextBoxCell
编写自定义排序函数,其中每次DataGridViewTextBoxCell.Value将从String
datatype解析为Date
数据类型,然后使用它进行比较
或:
看看这里
如果数据的类型合适,则应能正确工作/排序
希望有帮助 对应的DataGridViewColumn.ValueType
?正如@Neverhopeless的回答所示,您可能在列中使用了不理想的数据类型,即假定为日期的字符串。查看此MSDN文章:
QueDueDate.ValueType = GetType(Date)
QueDueDate.CellTemplate = New CalendarCell