473,837 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView duplicating nodes and also blowing up IE

I'm having some serious problems with the TreeView control.

I've got a control that inherits TreeView and has some methods that
firstly create a TreeNode then does some recursive procedure to add all
the children from a database of a sort. Then once this is complete I
clear the nodes, then add the TreeNode so it should be the only root
node.

The only problem is that for some very VERY strange reason there are
two root nodes, with duplicate child nodes. This is very bizare as
this.Nodes.Coun t returns 1 and base.Nodes.Coun t also returns 1, so
there SHOULD be 1 root node but there are two.

Also, I created another TreeView inherited control that would act as
the base for this other TreeView which does all the painting by me, so
that I can have different colors for highlighting and some other things
and to make it double buffered and not flicker like mad but when I use
this control as the base instead of the .NET one when I do
this.Nodes.Add it basically blows the control up in Internet
Explorer...

So basically the TreeView is driving me slightly nuts, either I can
have a TreeView with duplicate nodes that flickers when it updates the
nodes, else I can have one thats flicker free and nice but only works
when I add the nodes in edit mode, if I try adding them in code it
kills Internet Explorer...

any ideas? I'm already invoking back on the UI thread if it's needed to
add the root node, so I know the problems not that...

May 23 '06 #1
2 2262
Some code:

TreeNode rootNode = new TreeNode();
FormatNode(ref rootNode, service); // this passes a service class and
root and formats it text and color from the service classes details
rootNode = AddChildren(roo tNode); // add its children with recursive
procedure...

base.Nodes.Clea r();
if (this.InvokeReq uired == true)
this.Invoke(new UpdateRootHandl er(AddRoot),
rootNode);//this.Nodes.Add( rootNode);
else
this.Nodes.Add( rootNode);

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

private void AddRoot(TreeNod e node)
{
this.Nodes.Add( node);
}

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

private TreeNode AddChildren(Tre eNode node)
{
if (node == null)
{
Trace.WriteLine ("AddChildre n method has been passed a null
node");
return node;
}

Service parentService = (Service)node.T ag;
if (parentService == null)
{
Trace.WriteLine ("AddChildre n method has been passed a null
service instance");
return node;
}
// Retrieve list of child services
// & check the results returned are valid
ArrayList children = parentService.C hildren;
if (children == null || children.Count == 0)
{
Trace.WriteLine ("Service: " + parentService.N ame + " has no
children.");
return node;
}
// Increment each child service adding
// them one by one to the hierarchy
foreach (Service childService in children)
{
TreeNode childNode = null;

childNode = new TreeNode();
FormatNode(ref childNode, childService);
node.Nodes.Add( childNode);

// Recursively add a child's children
AddChildren(chi ldNode);
}

return node;
}

May 23 '06 #2
These issue's are starting to drive me slightly mad, I can't understand
why either of these problems are occurring... according to the nodes
collection there IS only one root, I really can't understand why two
are being displayed, it really is rather strange... and why the other
is blowing up I really don't know... I've spent ages debugging with
traces and attaching to Internet Explorer's process...

May 24 '06 #3

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

Similar topics

4
1285
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they appear in the underlying collection. However, the user must be able to reorder certain items in the collection--and, hence, the TreeView. I have created a context-sensitive menu that allows the user to move an item in the collection either up or...
2
1692
by: ThunderMusic | last post by:
Hi, while I'm searching into a treeview to find a specific node, I find the code duplicating treeview nodes I just can't figure out what's causing this behavior, maybe some of you already encountered this problem. Can someone help please? Here is the code of the functions causing this problem Thanks
4
5269
by: Jeroen Ceuppens | last post by:
Hi, I want to make something that adds a TreeNode to the end of TreeView, that TreeView Looks like + Level 1 + Level 2 + Level 3 - Level last
3
10154
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with that. Im trying for about 3 hours but can't get it to work. Thank you!
10
2371
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a top border. Is it possible to have more than 1 style at the same level (parent node) when using a SiteMap? I want it to appear something like this and I can only find a way to either have the border on all root nodes or none at all. In...
1
2223
by: | last post by:
What's the best way to create new nodes on a treeview 2.0 and save them to an xml file? Thanks, Victor
0
1456
by: Paulers | last post by:
Hello, I am trying to add sub items to a unique root node but it seems that it is duplicating the root node instead of placing subnode under it. Here is my code. Is ther anyone who can show me how to verify if the root node already exists and if it does add to the existing root node , else create a new one. Any help is GREATLY appreciated :)
18
15387
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and click to make multiple selections. Then when I simply click one item, all previous selections are gone. Thanks in advance.
0
3317
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
0
9846
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
10883
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...
1
10633
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10276
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
9412
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...
0
7007
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
5674
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...
0
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.