problem related to sorting of listview....
-
hello every one i am having problem related to listview.I want to sort partivular column of listview (ascending or descending)on label mouse click event.I knew how to sort whole listview for that my code is :- Private Sub lbl2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseClick Try Me.lst1.Sorting = SortOrder.Descending Catch ex As Exception MsgBox(ex.ToString) End Try End Sub please help.......
-
hello every one i am having problem related to listview.I want to sort partivular column of listview (ascending or descending)on label mouse click event.I knew how to sort whole listview for that my code is :- Private Sub lbl2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseClick Try Me.lst1.Sorting = SortOrder.Descending Catch ex As Exception MsgBox(ex.ToString) End Try End Sub please help.......
wow - are you trying to write unreadable code ? lbl2 and lst1 ? If the list control doesn't have a property for what column to sort by, you may have to sort your data yourself and just bind to a sorted collection.
Christian Graus Driven to the arms of OSX by Vista.
-
hello every one i am having problem related to listview.I want to sort partivular column of listview (ascending or descending)on label mouse click event.I knew how to sort whole listview for that my code is :- Private Sub lbl2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseClick Try Me.lst1.Sorting = SortOrder.Descending Catch ex As Exception MsgBox(ex.ToString) End Try End Sub please help.......
Okay, you defined your sorting order, but you forgot to sort! Add the following: Me.lst1.Sort()
-
wow - are you trying to write unreadable code ? lbl2 and lst1 ? If the list control doesn't have a property for what column to sort by, you may have to sort your data yourself and just bind to a sorted collection.
Christian Graus Driven to the arms of OSX by Vista.
hi this lst1 are lbl2 shortform written for listview and labels....
-
Okay, you defined your sorting order, but you forgot to sort! Add the following: Me.lst1.Sort()
hello The solution you gave is true for sorting whole listview but what if i want to sort particular column of a listview.... Me.lst1.Sorting = SortOrder.Descending the above syntax will sort whole listview... but not particular column ...so please help...
-
hello every one i am having problem related to listview.I want to sort partivular column of listview (ascending or descending)on label mouse click event.I knew how to sort whole listview for that my code is :- Private Sub lbl2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseClick Try Me.lst1.Sorting = SortOrder.Descending Catch ex As Exception MsgBox(ex.ToString) End Try End Sub please help.......
Sorting Listview columns in the .NET world is not simple. Let me see if I can give you the tools that I use for the same task. First, add this class to your project.
Imports System.Windows.Forms
Public Class C_ListviewComparer
Implements IComparer
#Region " Members "
Private _columnNumber As Integer
Private _sortOrder As SortOrder
#End Region
#Region " Constructors "
Public Sub New(ByVal ColumnNumber As Integer, _
Optional ByVal SortOrder As SortOrder = SortOrder.Ascending)
_columnNumber = ColumnNumber
_sortOrder = SortOrder
End Sub
#End Region
#Region " Methods "
#Region " ... Compare "
Public Function Compare( _
ByVal Lvi1 As Object, _
ByVal Lvi2 As Object) As Integer _
Implements System.Collections.IComparer.Compare
'-----------------------------------------------------
' Compare two subitem values in the same listview
' column
'-----------------------------------------------------
Select Case _sortOrder
Case SortOrder.Ascending ' Ascending sort order
Return CompareResult(SubitemValue(DirectCast(Lvi1, ListViewItem)), _
SubitemValue(DirectCast(Lvi2, ListViewItem)))
Case Else ' Descending sort order
Return CompareResult(SubitemValue(DirectCast(Lvi2, ListViewItem)), _
SubitemValue(DirectCast(Lvi1, ListViewItem)))
End Select
End Function
#End Region
#End Region
#Region " Procedures "
#Region " ... CompareResult "
Private Function CompareResult( _
ByVal FirstString As String, _
ByVal SecondString As String) As Integer
'-----------------------------------------------------
' Compare the subitem values to determine their sort
' order. For ascending sorts, the FirstString is the X
' value and SecondString the Y value. The values are
' reversed for a Descending sort.
'-----------------------------------------------------
If IsNumeric(FirstString) _
AndAlso IsNumeric(SecondString) Then
'** Numeric values
Return Val(FirstString).CompareTo(Val(SecondString))
ElseIf IsDate(FirstString) _
AndAlso IsDate(SecondString) Then
'** Date values