This is a migrated thread and some comments may be shown as answers.

Controlling Autocheck Child Nodes

2 Answers 135 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 23 Oct 2012, 09:40 PM
I'm using TriStateMode = true and AutoCheckChildNodes = true.  I would like to keep the behavior that checking a node automatically checks all children.  But if I uncheck all the children, the parent node also unchecks.  I would like to leave the parent node either checked or indeterminate (and possibly change the indeterminate image).

Even better, is it possible to modify this behavior for some parent nodes but not for other parent nodes?

Thank you,
Gary

2 Answers, 1 is accepted

Sort by
0
Doug
Top achievements
Rank 1
answered on 24 Oct 2012, 11:39 PM
I got it working well enough so far.  This will leave a parent node checkstate = indeterminate when the last of the child nodes is unchecked.  Otherwise, the checkstate changes follow the default behavior.  I'm not working in C# on this project yet, this is ASNA's Visual RPG.  You'll be able to translate it.  StopParentUncheck is a boolean variable.  "Begsr" are methods that return nothing.  trvPermissions is a RadTreeView.

    BegSr trvPermissions_SelectedNodeChanged Access(*Private) Event(*this.trvPermissions.SelectedNodeChanged)

        DclSrParm sender *Object

        DclSrParm e Telerik.WinControls.UI.RadTreeViewEventArgs

 

        StopParentUncheck = *False

 

    EndSr

 

    BegSr trvPermissions_NodeCheckedChanging Access(*Private)

        DclSrParm sender *Object

        DclSrParm e Telerik.WinControls.UI.RadTreeViewCancelEventArgs

 

        If trvPermissions.SelectedNode = *Nothing   

            Leavesr

        Endif

 

        Select

            When e.Node.Checked and ( e.Node = trvPermissions.SelectedNode ) and ( e.Node.Level > 0 )

                StopParentUncheck = NOT SiblingsSelected( trvPermissions.SelectedNode )

 

            When ( e.Node = trvPermissions.SelectedNode.Parent )

                e.Cancel = StopParentUncheck

 

        EndSl

 

    EndSr

    BegFunc SiblingsSelected Type( *Boolean )

        DclSrParm TheNode Type( RadTreeNode )

 

        DclFld SiblingNode Type( RadTreeNode )

 

        If TheNode.Parent = *Nothing

            Leavesr Value( *False )

        Endif

 

        ForEach SiblingNode Collection( TheNode.Parent.Nodes )

            If ( SiblingNode <> TheNode ) and SiblingNode.Checked

                Leavesr Value( *True )

            Endif

        Endfor

 

        Leavesr Value( *False )

 

    EndFunc




 

0
Stefan
Telerik team
answered on 26 Oct 2012, 02:50 PM
Hello Gary,

I am glad to hear that you have found a solution for this case. 

Another approach that comes to my mind is to turn off the AutoCheckChildNodes and the TriStateMode and handle all checks in the NodeCheckedChagned event.
 
Greetings,
Stefan
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
Treeview
Asked by
Doug
Top achievements
Rank 1
Answers by
Doug
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or