Skip to content

Iterating a listview

Ryan L

Asked Aug 14, 2006, 7:33 AM EDT1 answer
Share
LinkedInX
ive done this before but i cant remember how. I have a listview of items and I need to iterate through the listview to use the items. How do i do that? I cant use a foreach loop because it errors.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    ok, ive gotten past the last problem. now i need to iterate two listviews simultaneously. this is my code foreach (ListViewItem item2 in lvSrcFiles.Items) { int i = 0; item2.BackColor = Color.Yellow; item2.Font = new Font(item2.Font, item2.Font.Style | FontStyle.Bold); lvDestFiles.Items[i].BackColor = Color.Yellow; lvDestFiles.Items[i].Font = new Font(lvDestFiles.Items[i].Font, lvDestFiles.Items[i].Font.Style | FontStyle.Bold); Application.DoEvents(); FileInfo srcFile = new FileInfo(@item2.Text); srcFile.CopyTo(@"\\" + item.Text + @"\" + @lvDestFiles.Items[i].Text, true); item2.BackColor = Color.Empty; item2.Font = new Font(item2.Font, item2.Font.Style | FontStyle.Regular); lvDestFiles.Items[i].BackColor = Color.Empty; lvDestFiles.Items[i].Font = new Font(lvDestFiles.Items[i].Font, lvDestFiles.Items[i].Font.Style | FontStyle.Regular); Application.DoEvents(); i++; } however the problem is that the first item in lvDestFiles stays selected and never goes to the second item. why is it doing this and does anyone know why my text wont go back unbold when I tell it to go regular?
    0