modify list value with foreach iteration variable

B

Bob

Hi,
I have a list of widgets.
I want to iterate through the selected items collection and modify one of
the widgets properties.
I tried
foreach(widget w in lst.SelectedItems)
w.MyProperty = something;
but I get a message saying "Cannot modify members of w because it is a
foreach iteration variable"
What is the point of iteration if you can't modify the objects?
Thanks
Bob
 
B

Barry Kelly

Bob said:
foreach(widget w in lst.SelectedItems)
w.MyProperty = something;
but I get a message saying "Cannot modify members of w because it is a
foreach iteration variable"

What is widget? What is lst? What is MyProperty?
What is the point of iteration if you can't modify the objects?

You can modify the objects. You can't modify the collection, though. If
modifying the object would cause it to modify the collection, then that
isn't allowed.

I think your complaint would be more meaningful if it was precise!

-- Barry
 
B

Bob

Hi Barry,
Thanks for your reply.
Problem solved. My mistake was assuming that a listbox items collection
could have it members modified.
regards
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top