473,465 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3695
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: 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
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.