I got a big problem. I try to load data to listbox from a file, but when I load it I got an exception at last line of file. It says "Value cannot be null. Parameter name: item". I use this code
ListBox2.Items.Clear() 'clear listbox2
For i As Integer = 0 To ListBox1.Items.Count - 1
Dim read_text As New StreamReader(ListBox1.Items.Item(i).ToString, System.Text.Encoding.GetEncoding(1250)) ' listbox1.items.item(i) is the path of file I load data from
Try
Do While read_text.Peek >= 0
If read_text.ReadLine.ToString.Contains(":") Then 'dont load lines without ":" mark
ListBox2.Items.Add(read_text.ReadLine)
End If
Loop
read_text.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next i
Where is the problem? Can anybody help? ;)
ReadLine()
advances the file cursor. So you don't add the lines that you check. Therefore,ReadLine()
can returnNothing
eventually. And you must not addNothing
to theListBox
.