datagridview按两列排序 [英] datagridview sort by two columns

查看:113
本文介绍了datagridview按两列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关如何按两列对datagridview进行排序的帮助



我知道如何使用一列



this.dg.Sort(this.dg.Columns [Date],ListSortDirection.Descending);



这就是我按照它排序的方式日期,但我有另一个名为Time的列,我想用日期对它进行排序

I need help on how to sort datagridview by two columns

I know how to do it with one column

this.dg.Sort(this.dg.Columns["Date"], ListSortDirection.Descending);

this is how I sort it by dates, but I have another column called Time, and I want to sort it with dates together

推荐答案

DataGridView是UI组件。我希望在SQL本身或C#中对基础数据源进行排序,然后再将其绑定到DataGridView。
DataGridView is the UI component. I would rather sort the underlying datasource with in SQL itself or in C#, just before binding it to DataGridView.


为此,您需要定义自己的比较器并对其进行排序。



详细信息:

DataGridView中的多列排序 [ ^ ]

如何允许按自定义数据绑定中的多个列排序 [ ^ ]



试试!
For that you need to define you own comparer and sort it.

Full details here:
Multi Column Sorting in DataGridView[^]
How To Allow To Sort By Multiple Columns in Custom Data Binding[^]

Try out!


这篇关于datagridview按两列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆