Not so difficult. Answer is: don't make the form responsible for painting
the item... Make the item responsible for identifying itself and for
painting itself.
So if the other process changes Answer.Text from "Dog" to "Cat", then the
event contains a reference to Answer.MyIdentity (which could be a Guid or an
integer, or a random value or a known db id or anything that uniquely
identifies that particular answer from all other answers).
Then, in your form, you traverse the tree of Questions and Answers (I'd
suggest the Visitor pattern... see
http://www.dofactory.com/Patterns/PatternVisitor.aspx) and, when you find
the Answers in the tree, you pass in the Identity value and say "draw
yourself" if the identity matches. In other words, don't index directly...
search for it.
If you have less than 50 or so items on your form, this is not a noticably
less efficient idea.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
I'm thinking of building a complex data model with a number of nested
classes
but need to know something first. To simplify my question, let me present
you this sample data model
MainClass
Questions (collection)
Question (class)
Text (property)
Answers (collection)
Answer (class)
Text (property)
Here's what I'm looking to find out: Without specially preparing this data
model with all sorts of extra fields is there any way for the two
properties
shown to know what index of the collection(s) they're in, should the
property
value be changed?
For example, let's say that:
Questions(10).Text = "What's your favourite animal?"
and for this question:
Answers(3).Text = "Dog"
thus: Questions(10).Answers(3).Text = "Dog"
Now say that this property is changed externally by some process to "Cat".
What I would ideally like to do is have this change fire an event that
will
inform all listeners (ie. forms) change "Dog" to "Cat".
But I can't envision how to do this if this property isn't aware of where
it
sits in the hierarchy.
Any ideas?
--
Robert W.
Vancouver, BC
www.mwtech.com