.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to make a TreeNode in treeview as the 1st child node for every or specific Parent Treenode? w

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :Windows Application



How to  make a treenode  as the 1st child node for every parent node or for some specific parent nodes.

thanks in advance

View Complete Post

More Related Resource Links

Display error if a treeview root node contains a child node

I am having a treeview initially with a root node when form is loaded. I will add child node as some.txt file at the runtime by selecting an option as Addnew from contextmenu which was displayed when the user right clicks on the root node. Now what i need is if the tree has child node appended to the Root and if user tries to create a new node by clicking the option addnew from context menu i would like to display an error as only one child allowed.   Can any one help

How to put a TreeNode into Edit mode and make the text unselected

I have a c# app in which I would like to allow the user to enter new nodes in a TreeView control without having to use the mouse. I am able to intercept keystrokes in OnKeyDown, and the following code is working successfully: TreeNode newNode = new TreeNode( e.KeyData.ToString() ); Nodes.Add(newNode); LabelEdit = true; newNode.BeginEdit(); The problem is that the first letter in the node being edited is selected, which causes the following keystroke to replace the selected character.  Typing "HELLO" results in "ELLO", unless the user first presses the right-arrow key to deselect the selected first character. I tried setting e.Node.IsSelected = false in OnBeforeLabelEdit, but cannot because the IsSelected property is read-only. How can I programatically deselect the first character and position the edit cursor after the first character?

Displaying + on treeview node even when no child nodes are present


I have a treeview control that is working great, except that I would like the behavior of some nodes to display the + even though no child nodes exist yet. Meaning, I want my treeview control to look like this:

- RootNode
    + Node1
    + Node2
    + Node3

However, Nodes 1, 2, and 3 do not have any child nodes. From what I can see the + or - does not display if there are no child nodes, but I would like to see the + appear even though there are no child nodes. I want to do this because I want to create the child nodes upon expanding the parent node (Node1 for example).

Is this possible?



How to make a wpf child window follow it's parent




I've been trying to make a child window follow it's parent, I've bound the child's Top and Left properties to it's parent and that works for resizing of the parent and when the parent is dragged around the screen.  However I've hit a problem when I maximize and minimize the parent the child doesn't match it's size. I've watched the values of the parents Top and left in the debugger and it seems to get set twice once with a value that matches the new size and again with it's previous value and I guess this is whats making the child window appear incorrectly. I'm starting to think that just binding to the parents Top and Left properties isn't going to work. Is there a better approach to achieve this?



TreeView with parent to single child relation from multiple children c#



how to populate treeview  with a child node and with all its parent nodes





       -----a11 // if selected i want to draw treeview with its all parents






Problem to delete treeNode along with child nodes.



i have a treeView which display organization chart as hierarchical view. i want when end-user remove a treeNode, all childs of the selected node also being removed and then update database. to do this, i've used this code :

private void btnDeleteReceiver_Click(object sender, EventArgs e)

private void DeleteNode(TreeNode node)
      foreach (TreeNode childNode in node.Nodes)
      TestDataSet.ReceiversRow receiver = node.Tag as TestDataSet.ReceiversRow;

as u see in above code, i have a recursive method which delete all child nodes of the parentNode. but i'm facing a problem to delete all childs of the node. this loop could not iterate all childs node correctly. i don't know

WPF Selected xml node from treeview, I want to populate a datagrid with that node and all child node

I have populated a tree view from a xml.  I know want to take the node and all children that has been selected by double clicking on the tree node and populate a data grid.

text appears when treenode is partially visible to treeview


Hi all,

Like in Windows Explorer, when the specific treenode is partially visible and the mouse is hovered over, the tooltip like text window will appear.

Just wondering is there a similar build-in functionality in treeview?

From what I understood, this text window seems not a tooltip control per se. What is it and how it is implemented?


It's a WinForm app with C#, and I'm using .net 4.0 & VS 2010.



GridView Parent Child View with JQuery Effects

I was just checked how to add some more cool effects to the GridView control using JQuery. In this post I will display parent-child data in the GridView control with some help of the wonderful JQuery library.

Let's first populate the GridView control.

Display homepage node along with child nodes


If the first Sitemap node is your homepage/default and all other nodes are supposed to be children / grandchildren of the first sitemap node in a web.sitemap, how do I set up my web.sitemap to enable me to display my cssFriendlyMenu with the homepage node along with the nodes that are 1 level down from it at the same time as in :

Home   Products   Services   About us


...or is it not possible to have the first sitemap node displayed along with the nodes that are 1 level down from it?  Do I need to have a different starting node rather than my homepage node?

How to keep the hover for Parent menu and set the selected menu item css for child menu item?



I'm using cssfriendly control adapter for menu. My asp.net menu control's datasource is a sitemap file I'm using which contains all the urls.

I have the following questions:

  1. Is there a way to keep the parent menu item hovered while hovering over the respective child menu items?
  2. Is there a way to keep the child menu item selected? I am able to set the css for the parent menu, however I was wondering if the same is possible with the child items.

Please help! Smile


Moneka Smile

way of calling "javascript function of parent window from child window."

The article way of calling "javascript function of parent window from child window." was added by raja.s on Sunday, June 06, 2010.

Hi,Here i am going to explain how to call the javascript function of a parent window from the child window(pop-Up).Some may know before reading this post.Parent Java Script Function:script language="Javascript" type="text/javascript">

Treeview: Select all children if Parent is selected etc...



I'm using a Treeview with  ShowCheckBoxes="All" , so basically I have a tree with all CheckBox Nodes. I'm using the TreeView inside an update panel, and populate the Tree code behind dynamically.

My requrements are the following:

1) Select all the children if parent is selected,

2) When parent is selected, and if we de-select a child, set parent unselected

3) Track if new nodes were selected and previously selected nodes were de-selected (becasue I need to update the database according to the selections in the Tree)

For above 1, I do the following:

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        foreach (TreeNode node in TreeView1.Nodes)
            TreeNodeCollection col = node.ChildNodes;
            //select all children when the parent is checked
            if (col != null && node.Checked)

Addressing a specific node with CSS Friendly Control Adapters


Hello everybody,

I like the concept of the friendly control adapters, but I'm not sure if I can use them for my purpose.
My whole menu basically consist of one image, which itself contains the images for each menu item (is that understandable?).

Each menu item then displays only a certain part of the image.
I do this by shifting the background-position.

#navigation li#home a{
background-position:0px 0px;

/* Registration */
#navigation li#registration a:link, li#registration a:visited {
background-position:-106px -34px;

#navigation li#registration a:hover, li#registration a:focus {
background-position:-106px 0px;

/* Administration */
#navigation li#administration a:link, li#administration a:visited{
background-position:-212px -34px;

#navigation li#administration a:hover, li#administration a:focus{
background-position:-212px 0px;


I would like to do the same now with CSS Friendly, but I don't see how I can address each individual menu item node.
In static HTML I can give each link an ID (i.e. #administration), but I don't see how to do this with the asp:Menu control and CSS Friendly.

Can someone help me?

Thanks a lot,

(Imperfect) Solution to TreeView Postback / Client-Side Node Selection Issue


I've seen this question posted on all corners of the web... "How do I disable "AutoPostBack" on the ASP.NET 2.0 TreeView control?!"  Unfortunately, most of the answers either don't work, miss the point (don't work right), or boil down to "You can't do it."  I happen to know that this behavior worked perfectly in the IEWebControls TreeView that Microsoft released as an add-on prior to ASP.NET 2.0, however.  So I set out to find a solution for the ASP.NET 2.0 TreeView issue.

In a nutshell, the behavior that I and others are looking for is to have a TreeView rendered in a page that allows the user to expand, contract, and select nodes within the TreeView without causing a PostBack to the server.  This implies two things: (1) the most recently-selected node should be recorded as the currently-selected node [i.e., at PostBack time, the most-recently selected node is actually represented as the SelectedNode]; and (2) the selected node should exhibit the SelectedNodeStyle as specified in the TreeView declaration.

It appears that the TreeView engineers saw only two possible outcomes from selecting a leaf node in a tree: (1) immediately posting back to the server, or (2) immediately navigating to another web page.  They apparently did not consider option (3) just allowing selection in-place on the client, while waiting for a click on so

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend