在C#中排序dataGridView列? (Windows窗体) [英] Sort dataGridView columns in C# ? (Windows Form)

查看:150
本文介绍了在C#中排序dataGridView列? (Windows窗体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,我从一个sql表绑定,在那个DV我有这些属性:Id,名称和价格。当我将名称列的SortMode设置为自动,并且我点击这一列的标题时,我可以根据名称的第一个字母对这个dv进行排序,这样我可以根据他们的第一个字母(Acumulator,Boat,可口可乐,发动机等)。

有没有一种方法可以在没有点击列名头部的情况下发生。我正在寻找一些代码,将在窗体加载时完成这项工作。

解决方案

在DataGridView上有一个名为Sort的方法:

  this.dataGridView1.Sort(this.dataGridView1.Columns [Name],ListSortDirection.Ascending); 

这将以编程方式对datagridview进行排序。


I have a datagridview that i bind from an sql table, in that dv i have those attributes: Id, Name and Price. When i set the SortMode of the Name Columns to Automatic and i click on the header of this column i can sort this dv based on the first letter of the Name, this way i can order products based on their first letters ( Acumulator, Boat, CocaCola, Engine etc).

Is there a way this thing to happen without clicking the header of the column Name. I am looking some code that will do this job when the form will load.

解决方案

There's a method on the DataGridView called "Sort":

this.dataGridView1.Sort(this.dataGridView1.Columns["Name"], ListSortDirection.Ascending);

This will programmatically sort your datagridview.

这篇关于在C#中排序dataGridView列? (Windows窗体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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