vb.net关于ListView显示数据的问题,我每刷新一次序号就重复一次
如图,代码如下
Sub Main()
path = GetINI("配置信息", "yxPath", "", "D:\我的信息配置\test.ini").ToString
Try
'读取文件内容
Dim objFile As New System.IO.StreamReader(path, System.Text.ASCIIEncoding.Default)
Dim strContents As String
strContents = objFile.ReadToEnd()
objFile.Close()
objFile.Dispose()
Dim mhs As MatchCollection
Dim re = New RegExp
re.Global = True
re.Pattern = "\[\D{3,8}\]" '同样是匹配地址
mhs = re.Execute(strContents)
Dim MyValue As String
Dim UserName As String
Dim ServerName As String
Dim Remark2 As String
Dim StartTime As String
For i As Integer = 1 To mhs.Count()
MyValue = mhs(i - 1).Value
MyValue = MyValue.Replace("[", "")
MyValue = MyValue.Replace("]", "")
UserName = GetINI(MyValue, "UserName", "", path)
ServerName = GetINI(MyValue, "ServerName", "", path)
Remark2 = GetINI(MyValue, "Remark2", "", path)
If Remark2 = 0 Then
Remark2 = "否"
Else
Remark2 = ""
End If
StartTime = GetINI(MyValue, "StartTime", "", path)
ListView1.Items.Add(i.ToString)
ListView1.Items(i - 1).SubItems.Add(MyValue)
ListView1.Items(i - 1).SubItems.Add(UserName)
ListView1.Items(i - 1).SubItems.Add(ServerName)
ListView1.Items(i - 1).SubItems.Add(Remark2)
ListView1.Items(i - 1).SubItems.Add(StartTime)
Next
Catch ex As Exception
MessageBox.Show("帐号路径为不对或帐号格式不正确")
End Try
End Sub
'调用
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Main()
End Sub