This is very easy. Look at my solution. Here I am trying to read a text file with countries listed and then add each line to the CheckedListBox.
You cannot use
Items.Add()
The correct way is ,
Items.Insert(<index>, <string>)</string></index>
with proper parameters.
Check my code below.
private void button1_Click(object sender, EventArgs e)
{
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\srikaran\Desktop\Countries.txt");
while ((line = file.ReadLine()) != null)
{
ChkListBox1.Items.Insert(counter, line);
counter++;
}
file.Close();
}
By default the items are not checked.
Try this code and let me know if you have any issues getting this output.
Good luck.