在Datagridview中排序日期

在Datagridview中排序日期

本文介绍了在Datagridview中排序日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用vb.net2010. (快递)

我目前正在为自己编写一些软件,需要指导.

我在带有日期列的表单上有一个datagridview. (column0)

我正在尝试按要发送的日期进行排序,但只会按日期(dd)进行排序,而不是按整个日期(dd/mm/yyyy)进行排序,从而导致月份和年份无法排序.

(输出示例):
#1-01/03/2012
#2-02/01/2010
#3-2011年3月2日

我需要的是按完整日期顺序排列的日期:

#1-02/01/2010
#2-2011年3月2日
#3-01/03/2012


到目前为止,我有以下代码可以对列进行排序:

Hi all,
I am using vb.net2010. (express)

I am currently writing a bit of software for myself and need guidance.

I have a datagridview on a form with a date column. (column0)

I am trying to sort this by date desending but it will only sort by the day (dd) and not the whole date (dd/mm/yyyy) which leaves the months and years unsorted.

(example of output):
#1 - 01/03/2012
#2 - 02/01/2010
#3 - 03/02/2011

what i require is the dates in complete date order:

#1 - 02/01/2010
#2 - 03/02/2011
#3 - 01/03/2012


I have the following code to sort the column so far:

AppointmentsDataGridView.Sort(AppointmentsDataGridView.Columns(0), System.ComponentModel.ListSortDirection.Descending)

我尝试了以下操作引发错误:

I have tried the following which throws an error:

AppointmentsDataGridView.Sort(AppointmentsDataGridView.Columns(0), System.ComponentModel.ListSortDirection.Descending = ("dd/mm/yyyy"))

有人知道如何使它正常工作.

有人告诉我确保Date列是日期类型而不是字符串",我已将其作为Access数据库列类型.我已将其设置为Date,但它仍不会按整个日期对datagrid视图中的列进行排序.


非常感谢.

Has anybody got any ideas how to get this working correctly.

I have been told " Make sure the Date column is a date type and not a string " which i have taken as the access database column type. I have set this as Date but it still won''t sort the column in datagrid view by the whole date.


Many Thanks in advance.

推荐答案


这篇关于在Datagridview中排序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:13