2017-08-08 78 views
-1

如何對列表視圖中的數據進行排序? 我想在列表視圖框中對數據文本文件進行排序。 但我的代碼只讀取文件,而不是排序數據。vb.net如何在listview中對數據進行排序?

第一數據

2011-03-09 11:03:02 
2011-03-09 10:03:12 
2011-03-09 12:03:07 
2011-03-09 07:04:02 
2011-03-09 01:45:04 
2011-03-09 11:56:02 
2011-03-09 11:46:03 
2011-03-09 11:03:42 
2011-03-09 01:33:02 
2011-03-09 12:23:05 
2011-03-09 08:13:12 
2011-03-09 09:03:01 
2011-05-05 15:05:42 
2011-05-05 01:33:12 
2011-05-05 12:23:15 
2011-05-05 03:13:22 
2011-05-05 04:03:31 

.................... (200文件) 我想

2011-03-09 01:33:02 
2011-03-09 01:45:04 
2011-03-09 07:04:02 
2011-03-09 08:13:12 
2011-03-09 09:03:01 
2011-03-09 10:03:12 
2011-03-09 11:03:42 
2011-03-09 11:46:03 
2011-03-09 11:56:02 
2011-03-09 12:03:07 
2011-03-09 12:23:05 
2011-05-05 01:33:12 
2011-05-05 03:13:22 
2011-05-05 04:03:31 
2011-05-05 12:23:15 
2011-05-05 15:05:42 
........... 
+0

請給你試了一下代碼,你用什麼樣的技術,什麼具體的問題IST一些更多的信息。 – PhilMasterG

+0

請閱讀[問]並參加[旅遊]。這不是免費的代碼寫入服務 – Plutonix

回答

0

如果您已經將這些加載到陣列中,這可以很容易地完成:

Array.Sort(myArray) 
0

你會用eg一個ListBox而不是ListView爲您的需要。請注意在添加項目之前使用下面代碼中所示的Array.Sort方法。這應該也適用於ListView。

Imports System.IO 
Public Class Form1 
    Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click 
    Dim arrPointList() As String 

    ListBox1.Items.Clear() 

    Try 
     '--- read DateTime as text to array ---------- 
     arrPointList = File.ReadAllLines("D:\file-date-time-values.txt") 
     '--- sort array ----- 
     Array.Sort(arrPointList) 
     '--- Dim sLine As String = Join(arrPointList, ",") 
    Catch ex As Exception 
     '--- log message ---------- 
     MessageBox.Show("Check if file exists!", "Reading error!", MessageBoxButtons.OK, MessageBoxIcon.Error) 
     Exit Sub 
    End Try 

    For Each myLine In arrPointList 
     ListBox1.Items.Add(myLine) 
    Next 
    End Sub 

結果:

enter image description here

相關問題