在自动更新程序中看到的有用的代码段。测试一下Hashtable与ListView结合使用。
Public Class FrmHashTB Dim ht As New Hashtable Dim al As ArrayList Dim i As Integer Private Sub FrmHashTB_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load al = New ArrayList For i = 0 To 8 '添加了4个string Dim fileList(3) As String fileList(0) = String.Concat("i",i) fileList(1) = String.Concat("ix2=",i * 2) ht.Add(i,fileList) '初始化ht 添加到listview中。 Next End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click For i = 0 To ht.Count - 1 Dim fileArray() As String = CType(ht(i),String()) ListView1.Items.Add(New ListViewItem(fileArray)) Next End Sub Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click For i = 0 To ht.Count - 1 'lsv.Items(i).SubItems.Add(i.ToString) ListView1.Items(i).SubItems(3).Text = 50 Next End Sub Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged If Me.ListView1.SelectedItems.Count > 0 Then MsgBox(String.Format("text:{0},subtext(0):{1}",Me.ListView1.SelectedItems.Item(0).Text,Me.ListView1.SelectedItems(0).SubItems(0).Text)) 'Me.ListView1.Items(0).Text = Me.ListView1.Items(0).SubItems(0).Text End If End Sub End Class