473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Treeview -> TreeNode -> Object

I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
Messenger.

Is there a way that I can say something like

if treenode.tag is classContact then
string Surname = treenode.tag.surname

And somehow, each time, I create the node, I can assign the object of that
classContact to that node ?

I think the 'Tag' part of the TreeNode would be used, but not sure how...
Nov 17 '05 #1
6 3690
Yes, here is a sample as to how:

http://www.eggheadcafe.com/articles/...atabinding.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
Messenger.

Is there a way that I can say something like

if treenode.tag is classContact then
string Surname = treenode.tag.surname

And somehow, each time, I create the node, I can assign the object of that
classContact to that node ?

I think the 'Tag' part of the TreeNode would be used, but not sure how...

Nov 17 '05 #2
Thanks.

I'm looking to assign a class object that I have created, to my treenode
though...

Something like Treeview.SelectedNode.Tag = myObject..

And then later, I'd like to be able to access this objects properties via
the treenode.tag. Is this possible ?

Craig
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Yes, here is a sample as to how:

http://www.eggheadcafe.com/articles/...atabinding.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
Messenger.

Is there a way that I can say something like

if treenode.tag is classContact then
string Surname = treenode.tag.surname

And somehow, each time, I create the node, I can assign the object of
that classContact to that node ?

I think the 'Tag' part of the TreeNode would be used, but not sure how...


Nov 17 '05 #3
Yes,

myObjectType myObject = new myObjectType( ...);
....
treeView.SelectedNode.Tag = myObject;
....
((myObjectType)treeView.SelectedNode.Tag).MyObject Property = newValue;
....
HTH
Alex
"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
Thanks.

I'm looking to assign a class object that I have created, to my treenode
though...

Something like Treeview.SelectedNode.Tag = myObject..

And then later, I'd like to be able to access this objects properties via
the treenode.tag. Is this possible ?

Craig
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Yes, here is a sample as to how:

http://www.eggheadcafe.com/articles/...atabinding.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
Messenger.

Is there a way that I can say something like

if treenode.tag is classContact then
string Surname = treenode.tag.surname

And somehow, each time, I create the node, I can assign the object of
that classContact to that node ?

I think the 'Tag' part of the TreeNode would be used, but not sure how...



Nov 17 '05 #4
Right. That code sample does it with a DataRow. You could
just as easily do it with your class instead.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
Thanks.

I'm looking to assign a class object that I have created, to my treenode
though...

Something like Treeview.SelectedNode.Tag = myObject..

And then later, I'd like to be able to access this objects properties via
the treenode.tag. Is this possible ?

Craig
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Yes, here is a sample as to how:

http://www.eggheadcafe.com/articles/...atabinding.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
Messenger.

Is there a way that I can say something like

if treenode.tag is classContact then
string Surname = treenode.tag.surname

And somehow, each time, I create the node, I can assign the object of
that classContact to that node ?

I think the 'Tag' part of the TreeNode would be used, but not sure
how...



Nov 17 '05 #5
Thanks for the reply..

Getting an error:
Unable to cast object of type 'System.Int32' to type
'Address_Book_on_Steroids.classContact'.

on the following line:

MessageBox.Show(((classContact)tvMaster.SelectedNo de.Tag).Title);

Where

tvMaster is the TreeView


"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OF*************@TK2MSFTNGP09.phx.gbl...
Yes,

myObjectType myObject = new myObjectType( ...);
...
treeView.SelectedNode.Tag = myObject;
...
((myObjectType)treeView.SelectedNode.Tag).MyObject Property = newValue;
...
HTH
Alex
"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
Thanks.

I'm looking to assign a class object that I have created, to my treenode
though...

Something like Treeview.SelectedNode.Tag = myObject..

And then later, I'd like to be able to access this objects properties via
the treenode.tag. Is this possible ?

Craig
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
> Yes, here is a sample as to how:
>
> http://www.eggheadcafe.com/articles/...atabinding.asp
>
> --
> 2004 and 2005 Microsoft MVP C#
> Robbe Morris
> http://www.masterado.net
>
> Earn $$$ money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
>
>
> "Craig Lister" <in********@removethelisters.co.uk> wrote in message
> news:42***********************@news.zen.co.uk...
>>I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
>>Messenger.
>>
>> Is there a way that I can say something like
>>
>> if treenode.tag is classContact then
>> string Surname = treenode.tag.surname
>>
>> And somehow, each time, I create the node, I can assign the object of
>> that classContact to that node ?
>>
>> I think the 'Tag' part of the TreeNode would be used, but not sure how... >>
>
>



Nov 17 '05 #6
Hi Craig,

Your Tag contains a number (System.Int32) and trying to cast it to classContact will then fail.
Are all your tags classContact? Or are some of them different data types.

object o = tvMaster.SelectedNode.Tag
if(o is classContact)
{
classContact c = (classContact)o;
MessageBox.Show(c.Title);
}

On Sun, 24 Jul 2005 17:26:05 +0200, Craig Lister <in********@removethelisters.co.uk> wrote:
Thanks for the reply..

Getting an error:
Unable to cast object of type 'System.Int32' to type
'Address_Book_on_Steroids.classContact'.

on the following line:

MessageBox.Show(((classContact)tvMaster.SelectedNo de.Tag).Title);

Where

tvMaster is the TreeView


"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OF*************@TK2MSFTNGP09.phx.gbl...
Yes,

myObjectType myObject = new myObjectType( ...);
...
treeView.SelectedNode.Tag = myObject;
...
((myObjectType)treeView.SelectedNode.Tag).MyObject Property = newValue;
...
HTH
Alex
"Craig Lister" <in********@removethelisters.co.uk> wrote in message
news:42***********************@news.zen.co.uk...
Thanks.

I'm looking to assign a class object that I have created, to my treenode
though...

Something like Treeview.SelectedNode.Tag = myObject..

And then later, I'd like to be able to access this objects properties via
the treenode.tag. Is this possible ?

Craig
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
> Yes, here is a sample as to how:
>
> http://www.eggheadcafe.com/articles/...atabinding.asp
>
> --
> 2004 and 2005 Microsoft MVP C#
> Robbe Morris
> http://www.masterado.net
>
> Earn $$$ money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
>
>
> "Craig Lister" <in********@removethelisters.co.uk> wrote in message
> news:42***********************@news.zen.co.uk...
>>I have a treeview with a Root, a Contact Type, and a Contact. Like MSN
>>Messenger.
>>
>> Is there a way that I can say something like
>>
>> if treenode.tag is classContact then
>> string Surname = treenode.tag.surname
>>
>> And somehow, each time, I create the node, I can assign the object of
>> that classContact to that node ?
>>
>> I think the 'Tag' part of the TreeNode would be used, but not sure

how...
>>
>
>




--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PeteCresswell | last post by:
I've got a routine that loads a tree control. Works a-ok the first time around, then bombs the second. Works the third, bombs on the fourth....i.e. it works every other time it is invoked. ...
2
by: pei_world | last post by:
I wrote a class inherit from TreeNode of the system as follow, but when I try to use it with TreeView object, then it doesn't work, can anyone help? //============== code to use the inherited...
2
by: Sérgio Almeida | last post by:
greetings how can i check if a treeview contains a treenode with a specified text? i'm trying with the Nodes.Contains() method but doesn't work. Any ideas? Thanks Almeida
0
by: Craig Lister | last post by:
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN Messenger. Is there a way that I can say something like if treenode.tag is classContact then string Surname =...
2
by: rickpayne | last post by:
I've noticed the IE treeview asp.net web control has a heavey viewstate. I have been trying to use session variables to store its state instead of storing it in viewstate. Has anyone successful...
2
by: Slava ilyin | last post by:
Hi! Does anyone know how to get TreeNode RECT using VB.NET? My code is below seems to be incorrected. What is wrong? (sorry, I'm a novice in .NET) \\\ Private Declare Function SendMessage...
0
by: Luqman | last post by:
I have used menu control of VB.net 2005, and its opening like this :- Menu1>SubMenu1>SubSubMenu1 While I need this to display in a Hierarchy :- Menu1 SubMenu1 SubSubMenu1
5
by: Don | last post by:
I've created a small test class to extend the Treenode object and am having mixed success. In the Treeview's 'BeforeExpand' event I've used code from the help topic "Adding Custom Information to...
0
by: d_mike_2004 | last post by:
Hi, i have been trying to add a treenode into a Treeview. for example, say i have a tree as beloew: Node1 Node2 Node3 Node4 Node5 Node6
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.