关于listview的排序问题

firesky67 2004-04-14 09:31:50
我窗体上有个listview,把listview属性设置成控制面板那样的图标排列.还有三个radiobox,分别对应“升序”、“降序”和“不排序”。但是排序操作只在第一次选中某个radiobox的时候才执行。我哪里错了?请大家指点一下。
这三个radiobox对应的程序如下:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
ListView1.Sorting = SortOrder.Ascending
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
ListView1.Sorting = SortOrder.Descending
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
ListView1.Sorting = SortOrder.None
End Sub
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
firesky67 2004-04-17
  • 打赏
  • 举报
回复
还是不起作用 啊
Montaque 2004-04-14
  • 打赏
  • 举报
回复

' ColumnClick event handler.
Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the ListViewItemComparer implementation.
listView1.Sort()
End Sub

End Class

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class
ljmay168 2004-04-14
  • 打赏
  • 举报
回复
先判斷一下再排序,如:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
if RadioButton1.Checked Then
ListView1.Sorting = SortOrder.Ascending
End If
End Sub
TonyTonyQ 2004-04-14
  • 打赏
  • 举报
回复
在RadioButton的Click事件里写你那些代码,不要在CheckedChanged事件里写。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧