473,661 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

treenode - treeview

Hi,

I want to add some attributes to TreeNode, so I create a new class MyNode
that inheritance from System.Windows. Forms.TreeNode,
I want to TreeView use MyNode instead of TreeNode, so I can manipulate with
new attributes
How can? Please give me some ideas,
Thanks.

Because the TreeNode doesn't have Value Property which contents value behind
the diplayed text in TreeView
Nov 16 '05 #1
6 5725
RH
The TreeNode has a propery called Tag which is of type object. You can use
this property to store a single value or a whole object such as your MyNode
class.
"Dean L. Howen" <jm*@hotpop.com > wrote in message
news:uT******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I want to add some attributes to TreeNode, so I create a new class MyNode
that inheritance from System.Windows. Forms.TreeNode,
I want to TreeView use MyNode instead of TreeNode, so I can manipulate with new attributes
How can? Please give me some ideas,
Thanks.

Because the TreeNode doesn't have Value Property which contents value behind the diplayed text in TreeView

Nov 16 '05 #2
I agree with RH. Use the tag object to store any object you want. You can
inherit from treeview and treenode, but then you need to override a bunch of
stuff to get the strong typing you desire which would start to get messy.

--
William Stacey, MVP

"Dean L. Howen" <jm*@hotpop.com > wrote in message
news:uT******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I want to add some attributes to TreeNode, so I create a new class MyNode
that inheritance from System.Windows. Forms.TreeNode,
I want to TreeView use MyNode instead of TreeNode, so I can manipulate with new attributes
How can? Please give me some ideas,
Thanks.

Because the TreeNode doesn't have Value Property which contents value behind the diplayed text in TreeView


Nov 16 '05 #3
Below is my subclassed TreeNode with TreeView. On your windows you will add
the exTreeView and then add exTreeNode to the view. Now if you are like me
and need to display this new data then you will need to override the windows
painting with "unsafe protected override void WndProc(ref Message m)". I
think that's it but I might have left something out, this was pulled for
working code but it's rather large to post the whole thing here.

Hope this helps,
John

////////////////////////////
// makding a tree view
///////////////////////////
exTreeView tvMsg = new exTreeView()
.... put it some place

////////////////////////////
// Adding a node
////////////////////////////
exTreeNode node = new exTreeNode();
Node.Bmp = new Bitmap(128, 16, PixelFormat.For mat1bppIndexed) ;
this.tvMsg.Node s[idx].Nodes.Add(msgN ode);

/////////////////////////
// Tree node stuff
////////////////////////
namespace TreeStuff
{
[Serializable()]
public class exTreeNode : TreeNode
{
private Bitmap bmp;
public Bitmap Bmp
{
get { return this.bmp; }
set { this.bmp = value; }
}
public exTreeNode() : base()
{ }
}

public class exTreeView : TreeView
{
public exTreeView() : base()
{
}

protected override void OnPaint(PaintEv entArgs e)
{
e.Graphics.Fill Rectangle(Brush es.Black, e.ClipRectangle );
}

}
}

////////////////////////////////////
// painting the node
///////////////////////////////////
unsafe protected override void WndProc(ref Message m)
{
IntPtr inp;
NMCUSTOMDRAW *lp2;
NMHDR *lp;

inp=IntPtr.Zero ;

//Handle Notify message
if (m.Msg ==WM_NOTIFY)
{
lp=null;
lp=(NMHDR*)m.LP aram.ToPointer ();
{
//Message is NM_CUSTOMDRAW
if (lp->code ==NM_CUSTOMDRAW )
{
lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//It is a message Paint Item. Here we shall do some painting
if (lp2->dwDrawStage==C DDS_ITEMPREPAIN T) //CDDS_ITEMPREPAI NT
{
base.WndProc(re f m);
TreeViewPaint (ref m);
m.Result =(IntPtr)(0);
return;
}
else
{
//We shall return this value to get messages about item painting
m.Result =(IntPtr)CDRF_N OTIFYSUBITEMDRA W; ;
}

}
}
}
base.WndProc(re f m);
}

// This function paints additional info.
unsafe public void TreeViewPaint(r ef Message m)
{
NMCUSTOMDRAW *lp2;
System.Drawing. Graphics g;
exTreeNode node;

lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//Paint only this control items
//Now we have only one treeview so this code is commented
//if ((uint)this.Han dle !=lp2->hdr.hwndFrom )
//{return;}

//Get graphic device
g=System.Drawin g.Graphics.From Hwnd (this.tvMsg.Han dle );
//Get node which we are going to paint
node = (exTreeNode)thi s.tvMsg.GetNode At((int)lp2->x1+1,(int)lp 2->y1+1);

long x1=lp2->x1+node.Bounds .X +node.Bounds.Wi dth +5;
long y1=lp2->y1;
if(node.Bmp != null)
{
g.DrawImage(nod e.Bmp, x1, y1, node.Bmp.Width, node.Bmp.Height );
}

return;
}
Nov 16 '05 #4
I agree with RH solution. It's simpler than John'one ( it's more complex,
have to do many modify, but it's great. ).

Thank you for all your help!
"RH" <rh******@cog.c om> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
The TreeNode has a propery called Tag which is of type object. You can use
this property to store a single value or a whole object such as your MyNode class.
"Dean L. Howen" <jm*@hotpop.com > wrote in message
news:uT******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I want to add some attributes to TreeNode, so I create a new class MyNode that inheritance from System.Windows. Forms.TreeNode,
I want to TreeView use MyNode instead of TreeNode, so I can manipulate

with
new attributes
How can? Please give me some ideas,
Thanks.

Because the TreeNode doesn't have Value Property which contents value

behind
the diplayed text in TreeView


Nov 16 '05 #5
Hi,
According your solution, if I want to get the new attribute value, I have
more work to do, right?

Anyway, thank you to show me many solution.

-------------

"John J. Hughes II" <no@invalid.com > wrote in message
news:uq******** ******@TK2MSFTN GP11.phx.gbl...
Below is my subclassed TreeNode with TreeView. On your windows you will add the exTreeView and then add exTreeNode to the view. Now if you are like me and need to display this new data then you will need to override the windows painting with "unsafe protected override void WndProc(ref Message m)". I
think that's it but I might have left something out, this was pulled for
working code but it's rather large to post the whole thing here.

Hope this helps,
John

////////////////////////////
// makding a tree view
///////////////////////////
exTreeView tvMsg = new exTreeView()
... put it some place

////////////////////////////
// Adding a node
////////////////////////////
exTreeNode node = new exTreeNode();
Node.Bmp = new Bitmap(128, 16, PixelFormat.For mat1bppIndexed) ;
this.tvMsg.Node s[idx].Nodes.Add(msgN ode);

/////////////////////////
// Tree node stuff
////////////////////////
namespace TreeStuff
{
[Serializable()]
public class exTreeNode : TreeNode
{
private Bitmap bmp;
public Bitmap Bmp
{
get { return this.bmp; }
set { this.bmp = value; }
}
public exTreeNode() : base()
{ }
}

public class exTreeView : TreeView
{
public exTreeView() : base()
{
}

protected override void OnPaint(PaintEv entArgs e)
{
e.Graphics.Fill Rectangle(Brush es.Black, e.ClipRectangle );
}

}
}

////////////////////////////////////
// painting the node
///////////////////////////////////
unsafe protected override void WndProc(ref Message m)
{
IntPtr inp;
NMCUSTOMDRAW *lp2;
NMHDR *lp;

inp=IntPtr.Zero ;

//Handle Notify message
if (m.Msg ==WM_NOTIFY)
{
lp=null;
lp=(NMHDR*)m.LP aram.ToPointer ();
{
//Message is NM_CUSTOMDRAW
if (lp->code ==NM_CUSTOMDRAW )
{
lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//It is a message Paint Item. Here we shall do some painting
if (lp2->dwDrawStage==C DDS_ITEMPREPAIN T) //CDDS_ITEMPREPAI NT
{
base.WndProc(re f m);
TreeViewPaint (ref m);
m.Result =(IntPtr)(0);
return;
}
else
{
//We shall return this value to get messages about item painting
m.Result =(IntPtr)CDRF_N OTIFYSUBITEMDRA W; ;
}

}
}
}
base.WndProc(re f m);
}

// This function paints additional info.
unsafe public void TreeViewPaint(r ef Message m)
{
NMCUSTOMDRAW *lp2;
System.Drawing. Graphics g;
exTreeNode node;

lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//Paint only this control items
//Now we have only one treeview so this code is commented
//if ((uint)this.Han dle !=lp2->hdr.hwndFrom )
//{return;}

//Get graphic device
g=System.Drawin g.Graphics.From Hwnd (this.tvMsg.Han dle );
//Get node which we are going to paint
node = (exTreeNode)thi s.tvMsg.GetNode At((int)lp2->x1+1,(int)lp 2->y1+1);

long x1=lp2->x1+node.Bounds .X +node.Bounds.Wi dth +5;
long y1=lp2->y1;
if(node.Bmp != null)
{
g.DrawImage(nod e.Bmp, x1, y1, node.Bmp.Width, node.Bmp.Height );
}

return;
}

Nov 16 '05 #6
You can add any value you want to the exTreeNode and use it from code with
only a few changes. The problem is if you want to display the value in the
tree itself then you have to handle that condition. If you don't wish to
display the data in the tree then all you reall need to do is make the
exTreeNode and use it instead of TreeNode.

Regards,
John

"Dean L. Howen" <jm*@hotpop.com > wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
According your solution, if I want to get the new attribute value, I have
more work to do, right?

Anyway, thank you to show me many solution.

-------------

"John J. Hughes II" <no@invalid.com > wrote in message
news:uq******** ******@TK2MSFTN GP11.phx.gbl...
Below is my subclassed TreeNode with TreeView. On your windows you will

add
the exTreeView and then add exTreeNode to the view. Now if you are like

me
and need to display this new data then you will need to override the

windows
painting with "unsafe protected override void WndProc(ref Message m)". I think that's it but I might have left something out, this was pulled for
working code but it's rather large to post the whole thing here.

Hope this helps,
John

////////////////////////////
// makding a tree view
///////////////////////////
exTreeView tvMsg = new exTreeView()
... put it some place

////////////////////////////
// Adding a node
////////////////////////////
exTreeNode node = new exTreeNode();
Node.Bmp = new Bitmap(128, 16, PixelFormat.For mat1bppIndexed) ;
this.tvMsg.Node s[idx].Nodes.Add(msgN ode);

/////////////////////////
// Tree node stuff
////////////////////////
namespace TreeStuff
{
[Serializable()]
public class exTreeNode : TreeNode
{
private Bitmap bmp;
public Bitmap Bmp
{
get { return this.bmp; }
set { this.bmp = value; }
}
public exTreeNode() : base()
{ }
}

public class exTreeView : TreeView
{
public exTreeView() : base()
{
}

protected override void OnPaint(PaintEv entArgs e)
{
e.Graphics.Fill Rectangle(Brush es.Black, e.ClipRectangle );
}

}
}

////////////////////////////////////
// painting the node
///////////////////////////////////
unsafe protected override void WndProc(ref Message m)
{
IntPtr inp;
NMCUSTOMDRAW *lp2;
NMHDR *lp;

inp=IntPtr.Zero ;

//Handle Notify message
if (m.Msg ==WM_NOTIFY)
{
lp=null;
lp=(NMHDR*)m.LP aram.ToPointer ();
{
//Message is NM_CUSTOMDRAW
if (lp->code ==NM_CUSTOMDRAW )
{
lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//It is a message Paint Item. Here we shall do some painting
if (lp2->dwDrawStage==C DDS_ITEMPREPAIN T) //CDDS_ITEMPREPAI NT
{
base.WndProc(re f m);
TreeViewPaint (ref m);
m.Result =(IntPtr)(0);
return;
}
else
{
//We shall return this value to get messages about item painting
m.Result =(IntPtr)CDRF_N OTIFYSUBITEMDRA W; ;
}

}
}
}
base.WndProc(re f m);
}

// This function paints additional info.
unsafe public void TreeViewPaint(r ef Message m)
{
NMCUSTOMDRAW *lp2;
System.Drawing. Graphics g;
exTreeNode node;

lp2=(NMCUSTOMDR AW*)m.LParam.To Pointer ();

//Paint only this control items
//Now we have only one treeview so this code is commented
//if ((uint)this.Han dle !=lp2->hdr.hwndFrom )
//{return;}

//Get graphic device
g=System.Drawin g.Graphics.From Hwnd (this.tvMsg.Han dle );
//Get node which we are going to paint
node = (exTreeNode)thi s.tvMsg.GetNode At((int)lp2->x1+1,(int)lp 2->y1+1);

long x1=lp2->x1+node.Bounds .X +node.Bounds.Wi dth +5;
long y1=lp2->y1;
if(node.Bmp != null)
{
g.DrawImage(nod e.Bmp, x1, y1, node.Bmp.Width, node.Bmp.Height );
}

return;
}


Nov 16 '05 #7

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

Similar topics

5
10231
by: nevin | last post by:
Hi, If I have a TreeView with loads of Nodes and they all have children etc, how do I find the index of a given node when I only know the Text value? If I use TreeView.Nodes.IndexOf(new TreeNode(textvalueofname)) it always returns -1 and a TreeView.Nodes.Contains(etc.. always is false. I expect that it is only looking in the local Nodes collection rather than every single node in the TreeView. So how do I easily find any given node in...
9
12722
by: Mark Allison | last post by:
Hi there, I'm still very much a newbie to C#, and would like to derive from TreeNode to extend the TreeNode class. Here's test program: http://www.vkarlsen.no/pastebin/default.asp?id=4090 I get an error on line 0077 saying: "An unhandled exception of type 'System.InvalidCastException' occurred
6
3715
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 = treenode.tag.surname And somehow, each time, I create the node, I can assign the object of that classContact to that node ?
3
1831
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the answer. I'd appreciate and help. Thanks. What I'm doing is creating a treeview with the structure as follows (this is the expanded view): - Item Status - Item Status Details
3
4028
by: tanya foster | last post by:
Hello, I am re-writing a visual basic .net application(visual studio 2003) in an asp.net application(visual studio 2005). The vb.net application relied on a treeview and hence, treenodes. The treeview and treenode class in asp.net is limited compared to vb.net's. In vb.net, the treenode had a nextnode property which was equivalent to finding the next sibling of the treenode. asp.net's treenode has a child property and a parent property....
3
13806
by: Jeff | last post by:
Hey ..NET 2.0 I'm trying to search a TreeView control for a specific TreeNode The code below doesn't work because it only searches the the top level of the nodes. I would like to program it so that it can find a TreeNode anywhere in the TreeView... any suggestions on how to implement it ??
9
3695
by: vincent90152900 | last post by:
How to pop up different text base on the selected TreeNode? I want to pop up different Text base on the selected TreeNode of the TreeView component. So, I create a TreeView and a ModalPopupExtender. Following is my codes. <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"> <Nodes>...
0
3298
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. Provide following view properties to listview, through View menu a. Tile b. Icon
1
3271
by: AAaron123 | last post by:
If you see this posted twice - sorry. My news reader showed my first post as "No Longer Available" I have the following in a .css file. The treeNodes behave as if they were "a" elements. I can't get them to not respond to the mouse!
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2760
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 we have to send another system

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.