Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net DataGridView排序问题_.net_Vb.net_Sorting_Datagridview - Fatal编程技术网

.net DataGridView排序问题

.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 然后,在我向该列添加一堆行之后,我再执行一

因此,我有一个名为dtgQue的数据网格视图,这里是我的列的属性

'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