Robbe
Mon Dec 12 18:22:45 CST 2005
We agree to disagree on that one. There are all sorts
of business cases for us where using my approach
works out great. It drastically improved our
code reusability in some areas.
That said, I recognize it is not a one size fits all
approach to managing UI to data functionality.
In 2005, generics have helped us in this area
as well.
--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp
"Rick Elbers" <rick.elbers@chello.nl> wrote in message
news:oh0op15q3uld4ff53pho1vvoi55a1mgmjo@4ax.com...
> Two comments,
>
> 1) dont use c style casts if there is a better alternative.
> The better alternative is to create some sort union using
> implicit cast operators, then in the client use
>
> CustomObject obj = tvTre.SelectedNode.Tag as CustomObject;
> if (obj == null)
> //handle programmer errors with at least an ASSERT.
>
> 2) Databinding of a tree is an absurd idea, which reminds me at
> basic datastructure class. A tree is nothing but nodes like a
> list. In fact the best bst tree implementation is a skip list:-)
>
> So, what does this mean ? You can't ever want to databind
> a tree( which is nothing anyway) Its genericity stops when you have
> nodes from more then one table(see:
>
http://www.eggheadcafe.com/articles/treeview_databinding.asp)
>
> If you want to bind all nodes then the best approach seems
> to use a prototype tree of different nodetypes and construct
> new nodes from the prototype( see the pattern of the same name).
> Identifie your prototypenodes with for instance an enum.
>
> Then implement childdatabinding in the node. You can give the
> node a table, tableadapter and adaptermethod and basically
> you have databinding of the childnodes. Store the keyvalues in the
> node. Add things for adaptermethods with parameters. Make selectors
> from value( Where city = "Wageningen") or selectors from parent nodes
> (Where city = @City), the last simply implemented by passing the
> node's identifier level( see above)
>
>
>
> Rick
>
>
>
>
>
>
>
>
> On Sat, 10 Dec 2005 17:01:45 -0500, "Robbe Morris [C# MVP]"
> <info@eggheadcafe.com> wrote:
>
>>People typically create a small custom struct or
>>class with the properties they want exposed and
>>place it in the .Tag property.
>>
>>When they select a node, they get node,
>>
>>CustomItem test = (CustomItem)tvTree.SelectedNode.Tag;
>>
>>Debug.WriteLine(test.WhateverMyPropertyWas);
>>
>>You can also do this with datarows and institute
>>a sort of databinding.
>>
>>
http://www.eggheadcafe.com/articles/treeview_databinding.asp
>