473,386 Members | 1,812 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,386 software developers and data experts.

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.Count returns 1 and base.Nodes.Count 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 2236
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(rootNode); // add its children with recursive
procedure...

base.Nodes.Clear();
if (this.InvokeRequired == true)
this.Invoke(new UpdateRootHandler(AddRoot),
rootNode);//this.Nodes.Add(rootNode);
else
this.Nodes.Add(rootNode);

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

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

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

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

Service parentService = (Service)node.Tag;
if (parentService == null)
{
Trace.WriteLine("AddChildren method has been passed a null
service instance");
return node;
}
// Retrieve list of child services
// & check the results returned are valid
ArrayList children = parentService.Children;
if (children == null || children.Count == 0)
{
Trace.WriteLine("Service: " + parentService.Name + " 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(childNode);
}

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
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...
2
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...
4
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
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...
10
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...
1
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
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...
18
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...
0
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. ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.