在Listview Vb.net 中对列进行排序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17484357/
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
Sort a column in Listview Vb.net?
提问by shaik ibrahim
Sorry i think this might be duplicate question. I think so. Well i have done datagrid columns and it was able to sort with the code below but i tried to to this for lisview but it dosent seem to work. I want to sort list view based on a button click not column click. Is this even possible? I tried This link from MSDN but i didnt understand it. http://support.microsoft.com/kb/319399So below here is my code for sorting datagridview. Is it posible to apply it for lisview? Integer i is a global variable.
抱歉,我认为这可能是重复的问题。我想是这样。好吧,我已经完成了 datagrid 列,它能够使用下面的代码进行排序,但我试图对 lisview 进行此操作,但它似乎无法正常工作。我想根据按钮单击而不是列单击对列表视图进行排序。这甚至可能吗?我从 MSDN 尝试了这个链接,但我不明白。http://support.microsoft.com/kb/319399下面是我对 datagridview 进行排序的代码。是否可以将其应用于 lisview?整数 i 是一个全局变量。
i += 1
Dim x As Integer = grdDataGrid.CurrentCell.ColumnIndex
If i Mod 2 = 1 Then
'sort up
grdDataGrid.Sort(grdDataGrid.Columns(x), System.ComponentModel.ListSortDirection.Ascending)
ElseIf i Mod 2 = 0 Then
'sort down
grdDataGrid.Sort(grdDataGrid.Columns(x), System.ComponentModel.ListSortDirection.Descending)
采纳答案by Carlos Landeras
Check the answer at the following post:
检查以下帖子中的答案:
They give you several examples, but they also recommend ObjectListViewwho will make your job easier:
他们给了你几个例子,但他们也推荐ObjectListView谁会让你的工作更容易:

