Yay guys, it's me again.
I am using the code from here: http://www.daniweb.com/software-development/vbnet/code/370426 to sort my listview items. But I want something more 'dynamic': when I click on a header column, I want that it changes the sorting based on the column that has been clicked. here is my code:
'Classes usadas
Imports System.Math
Imports System.IO
Imports System.Threading.Thread
Public Class Main
'Define as variáveis
Dim CaminhoArquivo As String
Private Sub ProcuraDir(sender As System.Object, e As System.EventArgs) Handles btnProcuraPasta.Click
'Exibe o diálogo de procura
If ProcuraPasta.ShowDialog = DialogResult.OK Then
'Mostra o nome do arquivo na caixa de texto associada
Caminho.Text = ProcuraPasta.SelectedPath
CaminhoArquivo = ProcuraPasta.SelectedPath
For Each myCoolFile As String In My.Computer.FileSystem.GetFiles(CaminhoArquivo, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
Dim Arquivo As New FileInfo(myCoolFile)
Dim Tamanho As Decimal = Arquivo.Length
Dim TamanhoDividido As Decimal = 0
Dim TamanhoReal As String = ""
Dim ItemLista As New ListViewItem(Path.GetFileName(myCoolFile))
If Tamanho > 1073741824 Then
TamanhoDividido = Tamanho / 1073741824
TamanhoReal = Round(TamanhoDividido, 2) & "GB"
ElseIf Tamanho > 1048576 And Tamanho < 1073741824 Then
TamanhoDividido = Tamanho / 1048576
TamanhoReal = Round(TamanhoDividido, 2) & "MB"
ElseIf Tamanho > 1024 And Tamanho < 1048576 Then
TamanhoDividido = Tamanho / 1024
TamanhoReal = Round(TamanhoDividido, 2) & "KB"
ElseIf Tamanho < 1024 Then
TamanhoReal = Tamanho & " bytes"
End If
ItemLista.SubItems.Add(TamanhoReal)
ItemLista.SubItems.Add(Path.GetExtension(myCoolFile))
ItemLista.SubItems.Add("rwhsa")
ItemLista.SubItems.Add(Path.GetFullPath(myCoolFile))
ListView1.Items.Add(ItemLista)
Next
End If
GroupListView(ListView1, 2)
End Sub
Private Sub btnProcessar_Click(sender As System.Object, e As System.EventArgs) Handles btnProcessar.Click
For Each s As ListViewItem In ListView1.SelectedItems
MsgBox("Item selecionado: " & s.Text)
Next
End Sub
Public Sub GroupListView(ByVal lstV As ListView, ByVal SubItemIndex As Int16)
Dim flag As Boolean = True
For Each l As ListViewItem In lstV.Items
Dim strmyGroupname As String = l.SubItems(SubItemIndex).Text
For Each lvg As ListViewGroup In lstV.Groups
If lvg.Name = strmyGroupname Then
l.Group = lvg
flag = False
End If
Next
If flag = True Then
Dim lstGrp As New ListViewGroup(strmyGroupname, strmyGroupname)
lstV.Groups.Add(lstGrp)
l.Group = lstGrp
End If
flag = True
Next
End Sub
End Class
This is pretty much the last thing that I don't know how to do that I want to do :D And please ignore the code on the sub btnProcessar_Click
, it is useless by now!
Thanks!