when I add nodes (child nodes) to a treeview:
.Nodes.Add(cdl.FileName, ShowingText)

the first item shows as the 'key', like it was in VB6 - - -

However, when I want to refer to that key, I can't find anything in
Intellisense for that

like :

txtPath.text=TV1.SelectedNode. - - here's where I would have thought there
would have been a 'key' in the Intellisense - but it isn't

so how is it done?

Re: More Treeview questions by Robbe

Robbe
Sat Dec 10 16:01:45 CST 2005

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

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://robbemorris.blogspot.com





"Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
news:e$XTDOO$FHA.3852@TK2MSFTNGP14.phx.gbl...
> when I add nodes (child nodes) to a treeview:
> .Nodes.Add(cdl.FileName, ShowingText)
>
> the first item shows as the 'key', like it was in VB6 - - -
>
> However, when I want to refer to that key, I can't find anything in
> Intellisense for that
>
> like :
>
> txtPath.text=TV1.SelectedNode. - - here's where I would have thought there
> would have been a 'key' in the Intellisense - but it isn't
>
> so how is it done?
>
>
>
>



Re: More Treeview questions by Rick

Rick
Sun Dec 11 04:55:42 CST 2005

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


Re: More Treeview questions by Elmo

Elmo
Mon Dec 12 09:15:20 CST 2005

But in VS 2005 - the key is back in the treeview - -


"Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
news:e$XTDOO$FHA.3852@TK2MSFTNGP14.phx.gbl...
> when I add nodes (child nodes) to a treeview:
> .Nodes.Add(cdl.FileName, ShowingText)
>
> the first item shows as the 'key', like it was in VB6 - - -
>
> However, when I want to refer to that key, I can't find anything in
> Intellisense for that
>
> like :
>
> txtPath.text=TV1.SelectedNode. - - here's where I would have thought there
> would have been a 'key' in the Intellisense - but it isn't
>
> so how is it done?
>
>
>
>



Re: More Treeview questions by Elmo

Elmo
Mon Dec 12 12:20:10 CST 2005

Here's what I've found out
In VS.Net 2005 - if you give the node only one item, it's the Text property
of the node
If you feed it two items, the first one is the key.

Now - once you've given it the key, the Text property is just the visible
text
- there still is no 'key' property for nodes - - so how can I refer directly
to the key?



"Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
news:%23ZP7e7y$FHA.3064@TK2MSFTNGP10.phx.gbl...
> But in VS 2005 - the key is back in the treeview - -
>
>
> "Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
> news:e$XTDOO$FHA.3852@TK2MSFTNGP14.phx.gbl...
>> when I add nodes (child nodes) to a treeview:
>> .Nodes.Add(cdl.FileName, ShowingText)
>>
>> the first item shows as the 'key', like it was in VB6 - - -
>>
>> However, when I want to refer to that key, I can't find anything in
>> Intellisense for that
>>
>> like :
>>
>> txtPath.text=TV1.SelectedNode. - - here's where I would have thought
>> there would have been a 'key' in the Intellisense - but it isn't
>>
>> so how is it done?
>>
>>
>>
>>
>
>



Re: More Treeview questions by Robbe

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
>



Re: More Treeview questions by David

David
Fri Dec 16 14:42:31 CST 2005

Try using 'Name' instead of key - that should work.

David Wier
August Wind Software
http://aspexpress.com
http://aspnet101.com


"Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
news:%23Ye%23yi0$FHA.3568@TK2MSFTNGP09.phx.gbl...
> Here's what I've found out
> In VS.Net 2005 - if you give the node only one item, it's the Text
> property of the node
> If you feed it two items, the first one is the key.
>
> Now - once you've given it the key, the Text property is just the visible
> text
> - there still is no 'key' property for nodes - - so how can I refer
> directly to the key?
>
>
>
> "Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
> news:%23ZP7e7y$FHA.3064@TK2MSFTNGP10.phx.gbl...
>> But in VS 2005 - the key is back in the treeview - -
>>
>>
>> "Elmo Watson" <sputnik75043@No.Spam.Yahho.com> wrote in message
>> news:e$XTDOO$FHA.3852@TK2MSFTNGP14.phx.gbl...
>>> when I add nodes (child nodes) to a treeview:
>>> .Nodes.Add(cdl.FileName, ShowingText)
>>>
>>> the first item shows as the 'key', like it was in VB6 - - -
>>>
>>> However, when I want to refer to that key, I can't find anything in
>>> Intellisense for that
>>>
>>> like :
>>>
>>> txtPath.text=TV1.SelectedNode. - - here's where I would have thought
>>> there would have been a 'key' in the Intellisense - but it isn't
>>>
>>> so how is it done?
>>>
>>>
>>>
>>>
>>
>>
>
>