Notifications
Clear all

ordenar a listview

3 Posts
2 Usuários
0 Reactions
1,701 Visualizações
(@fazerbem)
Posts: 0
New Member
Topic starter
 

baixei este codigo abaixo, porem e somente para ListBox.

Como altero o mesmo para funcionar para ListView1 ?

Private Sub CommandButton6_Click() ' Ordenar
Dim i, j, x As Long, Temp As String
    With Me.ListBox2
        For j = ListBox2.ListCount - 1 To 0 Step -1
            For i = LBound(.List) To UBound(.List) - 1 Step 1
                If .List(i, 0) * 1 > .List(i + 1, 0) * 1 Then
                    For x = 0 To (.ColumnCount - 1) Step 1
                        Temp = .List(i, x)
                        .List(i, x) = .List(i + 1, x)
                        .List(i + 1, x) = Temp
                    Next x
                End If
            Next i
        Next j
    End With
End Sub
 
Postado : 26/06/2017 8:56 pm
(@neri-s)
Posts: 0
New Member
 

Bom dia Fazerbem

eu utilizo este comando, que consegui no forum...Não lembro o autor:


Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
' ordena a coluna ao clicar no título da mesma
ListView1.Sorted = False
ListView1.SortKey = ColumnHeader.Index - 1

If ListView1.SortOrder = lvwAscending Then
ListView1.SortOrder = lvwDescending
Else
ListView1.SortOrder = lvwAscending
End If

ListView1.Sorted = True

End Sub

Testa aí...

 
Postado : 27/06/2017 4:31 am
(@fazerbem)
Posts: 0
New Member
Topic starter
 

Muito Obrigado Neri S, seu codigo caiu aqui igual a uma luva.

Até a próxima amigao.

Andre

 
Postado : 27/06/2017 5:01 am