问题描述
我有一个datagridview,我从一个sql表绑定,在那个DV我有这些属性:Id,名称和价格。当我将名称列的SortMode设置为自动,并且我点击这一列的标题时,我可以根据名称的第一个字母对这个dv进行排序,这样我可以根据他们的第一个字母(Acumulator,Boat,可口可乐,发动机等)。
有没有一种方法可以在没有点击列名头部的情况下发生。我正在寻找一些代码,将在窗体加载时完成这项工作。
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窗体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!