This is because ReadLine
returns a single line, and you're iterating the characters in the line.
string line;
while ((line = file.ReadLine()) != null)
{
var index = int.Parse(line);
lstCheckBox.SetItemChecked(checked, true);
}
Should fix the problem.
Alternatively, you could use the following code instead (not using StreamReader
).
foreach (var line in File.ReadAllLines("checked.txt"))
{
var index = int.Parse(line);
lstCheckBox.SetItemChecked(checked, true);
}