vb.net 以编程方式对未绑定的数据网格视图进行排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24838753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sorting unbound datagridview programmatically
提问by Furqan Sehgal
I need to sort the datagridview programmatically. I googled a lot but nothing worked for me.
我需要以编程方式对 datagridview 进行排序。我用谷歌搜索了很多,但对我没有任何作用。
Datagridview is not bound to any datasource. Data is being added manually. My requirement is to sort it as when a 'Sort' button is pressed.
Datagridview 不绑定到任何数据源。正在手动添加数据。我的要求是在按下“排序”按钮时对其进行排序。
Can anyone suggest me code in vb.net?
谁能建议我在 vb.net 中编写代码?
回答by Sathish
Try like this
像这样尝试
DataGridView1.Columns(0)-> Give which column you want to sort
System.ComponentModel.ListSortDirection.Ascending-> Give direction of ascending or decending
DataGridView1.Columns(0)-> 给出要排序的列
System.ComponentModel.ListSortDirection.Ascending-> 给出升序或降序的方向
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
DataGridView1.Sort(DataGridView1.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub
回答by Scott
The code above works. You can, of course, choose any valid column. Here it is in C#, the only difference is the square braces []:gridview.Sort( gridview.Columns[0], System.ComponentModel.ListSortDirection.Ascending );
上面的代码有效。当然,您可以选择任何有效的列。这是在 C# 中,唯一的区别是方括号 []:gridview.Sort( gridview.Columns[0], System.ComponentModel.ListSortDirection.Ascending );

