bg***@yahoo.com wrote:
Hi,
Lets say I have a TreeView with nodes that represent objects of a
number of different types. Is there a way of associating the Set
method of each object with its node in the TreeView? That way when you
select a node in order to change its associated data, you have easy
access to its Set function.
The way I normally handel this situation is is to create an enum of
all the different types that the treeview contains. I then have a
string table which corresponds to each member of the enum. I can then
use these to set the Name member of each Node and hence establish from
that which type I'm working with.
I'm guessing there is an easier way of doing this...
Two approaches spring to mind:
- If all these objects have a Set method*, then pull that method out
into an ISettable interface that they all then implement. Then have each
TreeNode hold** a reference to an object of type ISettable which it can
use to get at its ISettable.
- If the objects 'setting' behaviour isn't uniform, define a delegate
type (from void to void, or whatever), then in the TreeNode hold** a
delegate to the object's DoWhatever method.
* If 'Set' is just an example, OK, but if not then it's stylsitically
not a very nice name for a method.
** Two ways to make a TreeNode hold an arbitrary extra piece of
information: lazy + dirty, use the Tag property; clean and not much more
work, derive from TreeNode a TreeNodeEx class that holds whatever
(strongly typed) extra information you need.
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version