Whenever I use a for loop so select each item in the Listbox Using Listbox.SetSelected(i) it overflows over the Listb开发者_Python百科ox. anyone has a solution?
Since you mention for
and overflow, I assume the problem is an index range; most .NET indexers are 0-based, so you need:
for(int i = 0 ; i < collection.Length ; i++)
{
collection[i].DoSomething();
}
Note also that in most cases foreach
is simpler and safer:
foreach(var item in collection)
{
item.DoSomething();
}
精彩评论