Good idea or bad idea?

P

pigeonrandle

Hi,
My application creates a project that is structured like a tree, so i
want to use a treeview to display it to the user.

Would it be a good idea to create the various parts of project as
classes inherited from TreeNode and then just add them to the treeview
(ie adding extra properties to the inherited classes to hold my data)?
This would make outputting the project as an xml file very simple as i
could just traverse the treeview and get the nodes to write their part
of the document.

Or is it a better idea to create separate classes to hold my data, and
place them in the .Tag of a normal treenode?

Or is their another way i should do this?

Basically, is mixing the 'data' with the UI a good idea? I thought i
read somewhere that it is a bad idea :(.

Cheers,
James.
 
T

Tom Dacon

The fact that you're asking this question shows that your subconscious is
trying to tell you that mixing UI and data classes is almost always a bad
idea. Generally one makes the data classes (business object classes)
independent of any particular type of user interface, because it gives one
the most flexibility in creating interfaces to the business objects - some
of which might not even be interactive user interfaces.

So plunking the object into the Tag property of a TreeNode isn't a bad idea,
or if you have a collection of those business objects at hand you might just
store in the Tag a value that you could use as a lookup into the collection
(an ID or other unique key). But "storing the object" in the Tag isn't
expensive anyway, since you're actually just storing a reference to the
object, which is probably just a four- or eight-byte value depending on
whether you're on a 32-bit or 64-bit operating system.

Tom Dacon
Dacon Software Consulting
 
P

pigeonrandle

Tom,
Cheers for your thoughts. I have already started rewriting what i had
'done' and was looking for somebody to slap me on the back and say
'shrewd move' :blush:).

Thanks again,
James.
 

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