Data binding question

D

deko

I have a dataset with tables that map to nodes in a TreeView.

+ Project1 |
+ ConfigA | txtDate
+ Project2 |
+ ConfigB |

On the form that contains the TreeView, there are controls that need to
display other various bits of data associated with each node when the node
is selected in the TreeView. This other data is stored in the same DataSet
in related tables.

So, for example, when I click on Project1, a text box on the form will show
the start date for that project.

I was thinking I could store a struct in the Tag property of each root node
and on NodeMouseClick, throw that structure at a method that updates the
controls of the form.

This means that when the form first opens, as I am creating the node array
for the TreeView from the DataSet, I need to stuff structs in the Tag of
each root node.

Is this utter insanity, or sound reasoning?

One potential complication is a popup form that is supposed to display
further details of the selected project. How would I get the data for that
popup form? Can I store that same struct in some property on the main form
and pass it to the constructor of the popup form when the OpenPopupForm
button is clicked?

Any suggestions welcome...
 
G

Guest

I store structs and / or classes in the Tag property of treenodes all the
time. I've found it to be an excellent approach.
Peter
 
D

deko

I store structs and / or classes in the Tag property of treenodes all the
time. I've found it to be an excellent approach.

Well, that's a vote of confidence, anyway.

As for data binding, I looked at that new BindingSource component (recent
dnrTV show on this), but what I'm trying to do just doesn't fit that mold.

There's a whole bunch of data behind each TreeNode. Some is displayed by
child nodes, some is displayed in other controls on the form that hosts the
TreeView, and still more is displayed in a popup from.

If I store a struct containing all this data in each root node's Tag, I can
get the data I need for the controls on the MouseNodeSelect event. As for
the popup form, I need some way to reference the node (that was previously,
but is no longer, selected) when the OpenPopupForm button is clicked. I
could copy the struct from the tag of the node to the tag of the button, but
that seem like a hack.

Anyway, thanks for the reply.
 
N

Nick Hounsome

Peter Bromberg said:
I store structs and / or classes in the Tag property of treenodes all the
time. I've found it to be an excellent approach.
Peter

IMHO An even better approach is to derive your own TreeNode and have a
typesafe property instead of using the Tag.

You can also push some of your logic into the node gives you more modular
code:
Pass your business object to the ctor and have it decide the text.
Have a bunch of derived types all implement an interface and you have a nice
way to do polymorphic node click behaviour.

The problem with Tag is that it is not clear which, if any, part of the code
uses it.

The same comments go for ListViewItem only more so because of the subitems.
 

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