469,889 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Data binding question

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...
Mar 5 '06 #1
3 1759
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"deko" wrote:
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...

Mar 5 '06 #2
>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.
Mar 5 '06 #3

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:4E**********************************@microsof t.com...
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.
Mar 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Marcin Floryan | last post: by
16 posts views Thread by D Witherspoon | last post: by
1 post views Thread by Patrick | last post: by
1 post views Thread by matty.hall | last post: by
reply views Thread by popsovy | last post: by
10 posts views Thread by Fares Eidi | last post: by
2 posts views Thread by Matthias | last post: by
19 posts views Thread by Larry Lard | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.