datagridview按两列排序

编程入门 行业动态 更新时间:2024-10-28 10:23:32
本文介绍了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按两列排序

本文发布于:2023-10-28 02:34:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:datagridview   按两列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!