你的代码没问题 我试过了~ 肯定是其他地方出错了
我的测试代码:
Imports
Public Class Form1
Private Sub writeToListView()
Dim fs As FileStream = New FileStream("E:\fileName.txt", FileMode.Open)
Dim sr As StreamReader = New StreamReader(fs)
Dim str As String = sr.ReadLine()
Dim substr(0, 2) As String
substr(0, 0) = str.Substring(0, str.IndexOf(" ")) '3
substr(0, 1) = str.Substring(str.IndexOf(" ") + 1, str.LastIndexOf(" ") - str.IndexOf(" ") - 1) '0
substr(0, 2) = str.Substring(str.LastIndexOf(" ") + 1, str.Length - str.LastIndexOf(" ") - 1) '222
ListView1.Items.Add(substr(0, 0))
ListView1.Items.Add(substr(0, 1))
ListView1.Items.Add(substr(0, 2))
For i As Integer = 0 To ListView1.Items.Count - 1
Select Case ListView1.Items(i).SubItems(0).Text
Case Is = 0
ListView1.Items(i).ForeColor = Color.Blue
Case Is >= 1
ListView1.Items(i).ForeColor = Color.Green
End Select
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call writeToListView()
End Sub
End Class