How to sort listview according to a specific column

0

I have a listview that shows more or less the following:

ID    NOME    IDADE
0     Luis     19
1     Julio    33
2     Marcio   27

The problem is that when the ID arrives at 10, the listview starts putting the 11, 12, 13 ... before the 2, getting something like:

ID    NOME     IDADE
0     Luis      19
1     Julio     33
11    Claudio   33
12    Felipe    33
2     Marcio    27

I wanted to know how to fix this, making 11, 12, 13 ... come after 10, and so on.

I recently discovered that the problem is in code that reads files (information is taken from XML files)

Dim DirDiretorio As DirectoryInfo = New DirectoryInfo(pedidosPath)
Dim oFileInfoCollection() As FileInfo
Dim oFileInfo As FileInfo
Dim i As Integer
oFileInfoCollection = DirDiretorio.GetFiles()
For i = 0 To oFileInfoCollection.Length() - 1
    oFileInfo = oFileInfoCollection.GetValue(i)
    'Pega os dados do arquivo
Next

With a MessageBox I discovered that it takes 10, 11, 12, ... before 2. Any alternative code?

    
asked by anonymous 08.02.2016 / 00:31

1 answer

-1

Just use the ListViewItemSorter property of the ListView, to sort by a specific column. In the example below I am sorting through the first column.

Dim ListView1 As New ListView
Dim lvwColumnSorter As ListViewColumnSorter

lvwColumnSorter = New ListViewColumnSorter()

lvwColumnSorter.SortColumn = ListView1.Columns(0).Index
lvwColumnSorter.Order = SortOrder.Ascending

ListView1.ListViewItemSorter = lvwColumnSorter

ListView1.Sort()

In the links below there is more information about sorting columns in ListView.

link

link

    
15.02.2016 / 13:46