Normally, in other languages like Delphi, I used to clear the contents
of the Listbox
before I fill it up with data. My C# code looks like this:
private void btnCheck_Click(object sender, EventArgs e)
{
listBox.Items.Clear();
foreach (string s in displayList)
{
listBox.Items.Add(s);
}
}
I noticed that whenever you enter values to the Listbox, instead of
removing the previous entries,
the succeeding values only gets appended. For example, on the first
pass I enter "abc", the output
is "abc". On the second pass, I enter "123", the values will now be
"abc" and "123" one for each line!
Is there a workaround on this? How do I clear the contents of the
Listbox? By the way I use Arraylist to store data prior to displaying
it to the Listbox.