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

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

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

Posted By:      Posted Date: August 23, 2010    Points: 0   Category :ASP.Net


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)

View Complete Post

More Related Resource Links

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






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

VS2008 and C#: How to create a short cut for a selected item in a ListView/TreeView ?

How to create a short cut for a selected item from a ListView/TreeView ? Is it possible to provide a smaple code ? Thanks,

Excel 2003 pivot table - parent showing grand total than the sum of its children

All, In Excel 2003, I have a product hierarchy, for simplistic sake lets say it goes A > B > C > model nbr.  I have filtered on model nbr 1.  I have the product hierarchy in my pivot table and unit cnt as the measure. Starting at level A in the hierarchy I am showing a total unit of 12000, if I drill down to B it still shows 12000, if I drill down to C it shows 100 and if I drill down to model nbr it shows me model nbr 1 with a unit cnt of 100. So my question is why are my parents not filtering the model nbr, it is taking the total for ALL records that have level A as their parent regardless of the model nbr? This does NOT happen in Excel 2007 or when I browse my cube in SSAS.

Multivalue parameters - Changing label if (Select All) is selected

I'm using SSRS 2005.  I have a report which has a multi value parameter.  When you click (Select All) the text in the parameter combobox shows all the names of the possible values.  Since this is my default it really looks tacky and hard to read. Is there a way I can have the text in the multi value parameter combobox say "ALL" or something else when (Select All) is checked?  

Treeview Parent

Hello! Short version: How to get the visual parent of a bound treeviewItem? (not actually a treeviewitem but my own object)   Long version: I know there are alot of posts about this problem, but I can't seem to get any of the solutions to work. I have this simple task(so I thought) to find the parent of an item in my treeview. The item is not a TreeViewItem it is my own type. The class I use to build the treeview has children of its own class, so its only one type of objects in the treeview. I want to be able to move any items into another so it becomes the child of the new item. This works well by adding it to the children property of my class. I do that by dragging a node onto another node. But how do I remove it from the original object? When I start dragging, the node becomes selected, and here is a perfect place to put the magic code. MagicTreeViewHelper.getTheFreakinParentNode(myDraggedObject). Please help me make this method!! ;) I cant go through the data and remove the child from all the other items because it is allowed for any item to be a child of multiple nodes. So I need to access the visual parent node which contains the bound object from which I'm dragging the item from. One solution that seems to be the answer everywhere I look is some variant of the code below: Already on the first line it fails, because I dont have TreeViewItems in my tree... Any s

mdi children from always goes under mdi parent controls

hi there in my application i have a mdi container and some mdi children forms. i putted some controls i mdi container but when i show mdi child form, the form goes behind the mdi parent controls and some part were not shown!!!! how to solve this?

mdi children from always goes under mdi parent controls

hi there in my application i have a mdi container and some mdi children forms. i putted some controls i mdi container but when i show mdi child form, the form goes behind the mdi parent controls and some part were not shown!!!! how to solve this?

Values in multiselect dropdown not getting selected when Select All option is selected


Values in multiselect dropdown not getting selected when Select All option is selected for a SSRS dropdown.

There are multiple dropdowns on the page. We have one dropdown whose output is being used to populate the second dropdown using a stored procedure. When we check the Select All checkbox on the dropdown then ideally upon page refresh all the values should get selected in the dropdown, but in this case the page refreshes back to the blank dropdown, forcing the user to select the values again. The next dropdown too does not get populated. This makes it impossible to run the report for all the cases by using Select All.

We ran the report on differnet database environments. My current location is Mumbai,India, the report worked fine when we ran it on a Bangalore,india database. This issue occurs when we try running it on a Chicago database server.

I am using SSRS 2005, SQL2005.

If anybody has faced such an issue earlier, please help me out here.  Thank you. 


selected option items in (multi-) select box on ASP pages are not highlighted if the select box is d


Dear community,

I've an asp application with vbs using input forms containing select objects with the property "multiple" specified. If the select object is disabled, the selected option items aren't highlighted. This behaviour occurs with IE8 and also with IE9. In earlier versions of IE everything worked fine. You can reproduce that also with a simple HTML page like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<Select style='width:200;height=200' disabled multiple>
 <option selected>option1</option>
 <option selected>option3</option>
 <option selected>option5</option>

<Select style='width:200;height=200' multiple>
 <option selected>option1</option>
 <option selected>option3</option>
 <option selected>option5</option>



Is there a workaround for that?

Thanks in advance!


How to handle treeview selected node changed event



From my below sample code, I don't want to use Sessions to handle each click event inside treeview selected node changed.

Secondly, if you suggest me to use treenode.SelectedValue then I would say my values are dyanmically generated.

Everytime a node a clicked, the selected node value is sent in the next request xml to get response and xml schema is different for each click. How do I handle this each click event other than using session variables. I thought of using Request.Item (and integrating with URL redirect property) but I don't want to use that.


Dim trNode As New TreeNode
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then        
            trNode.Text = "Not Postback"
            Session("Flag") = 1
        End If
    End Sub

Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TreeView1.SelectedNodeChanged
        If Session.Item("Flag") = 1 Then
            trNode.Text = "Is PostBack"
            Session("Flag") = 2
        End If

How to bind to a WPF TreeView's selected item?



Most of you probably know the excellent MVVM WPF TreeView article by Josh Smith (http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx).

Using the Family Tree demo (Text Search), can someone explain me how to bind a control's property (let's say, a TextBlock's Text property) to the selected item's Name property (PersonViewModel.Name) in the treeview? In essence, if the user clicks on "Sarah Applifunk", the TextBlock would show "Sarah Applifunk". Then if the user clicks on Maurice Winkleford, the TextBlock would update as such.

Of course I would like the TextBlock to look somehow like this:

<TextBlock Text="{Binding SelectedPerson.Name}" />

This *used* to work in my application using the IsSynchronizedWithCurrentItem="True" using lists, but the TreeView is somewhat more complex, isn't it?


jquery jstree and dynatree parent node don't get selected(asp.net mvc)


I have used jquery jstree and dynatree persistance example using check boxes and found the same logic The thing is that the if for example there is a parent and 4 child. a) i select all the 4 child (parent get auto selected) the 4 child and the parent node id get posted to the controller. b) But if i select less then 4 children (parent get auto selected) only child node ids get posted to the controller. Is there any way even if i select less then 4 children all my selected nodes included the parent get posted to the controller?

i wrote a method to conquor this but if i can do it in conventional way . it would be great. i hope some one has experience this problem and can help me out?

select record based on / match selected date

with the sql statement below, i try to select the records based on the selected date, it return no rows from adapter filled datatable. 
however, when i run the query in sql query in sql server studio management, it returns records. 
date format = 09/28/2010

string[] splitDT = txtSelectedDate.Text.Split('/');

            string strRearrangeDT = splitDT[0] + "/" + splitDT[1] + "/" + splitDT[2];

using (SqlConnection sqlconn = new SqlConnection(connstring))
                DataTable dt = new DataTable();
                string strSQL = "SELECT userclaim_details3.id, userclaim_details3.userclaimid, userclaim_details3.userid, userclaim_details3.childcategorytableid, userclaim_details3.statusid, " +
                         "userclaim_details3.amount AS amountname, userclaim_details3.remark AS remarkname, userclaim_details3.datecreated AS datecreatedname, " +
                         "userclaim_details3.datemodified, approvaltable.id AS Expr1, approvaltable.typename AS statusname, usertable2.id AS Expr2, usertable2.name AS uname, " +
                         "childcategorytable.id AS Expr3, childcategorytable.categor

How to multi select items in WPF Treeview using Shift Button


I have a requirement where i have to create a WPF Treeview, bind it to a dataset.
Then i have to provide functionality for user to select nodes either using Ctrl or multi select using Shift button.

I am able to write code to do all the tasks above except multi select using Shift button.
Following is my XAML for Treeview.

<TreeView Name="tvOutput" ItemsSource="{Binding}" Height="200" VerticalAlignment="Top" MouseMove="tvOutput_MouseMove" DragLeave="treeView_DragLeave" SelectedItemChanged="Tree_SelectedItemChanged">
                                <!-- This Style binds a TreeViewItem to a Node. -->
                                <Style TargetType="{x:Type TreeViewItem}">
                                    <Setter Property="IsEnabled" Value="{Binding IsEnabled, Mode=TwoWay}" />
                                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                                        <Trigger Property="IsEnabled" Value="True">
                                            <Setter Prop

TreeView - multi select - why so complicated?


I can’t understand why whoever implemented the TreeView implemented it such a way that it is impossible to easily extend to support multi selection (actually, why didn’t they add it to begin with????).


I was looking at how to implement this in my TreeView derived base class and implement it in a way that would not require any style or template changes per tree. I have spend some time looking at the implementation using Reflector, and it seems to me that ‘if only’ the TreeView.ChangeSelection had been exposed as a virtual method instead of internal, then it would have been possible to ‘hack’ it, but unfortunately this is not the case.


So – after a lot of searching I have not been able to find any solution which would require code changes only. Is it possible at all?.

Select List - Set the selected value


I am attempting to set the sletected value of a selectlist

ViewData["CompanyLocationID"] = new SelectList(
                , "CompanyLocationID"
                , "LocationName"
                , Convert.ToInt32(localCompanyLocationsContact.CompanyLocationID));

I have tried to set the value to an integer and to a string and just pass it in regular, but no matter what it never sets the selected value.  Is there something i am doing wrong?

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