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

check only parent while binding the data

3 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
karamjeet
Top achievements
Rank 1
karamjeet asked on 08 May 2012, 07:18 AM
I am using your RadTreeview to show my categories in parent child mode with code as

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><br><telerik:RadTreeView ID="RadTreeView1"<br>                                    runat="server" TriStateCheckBoxes="true" CheckBoxes="true" CheckChildNodes="false"><br>                                    <Nodes><br>                                    <telerik:RadTreeNode Text="hello" Value="hello"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true"><br>                                    <Nodes><br>                                    <telerik:RadTreeNode Text="hello11" Value="hello11"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello12" Value="hello12"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello13" Value="hello13"></telerik:RadTreeNode><br>                                    </Nodes><br>                                    </telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello2" Value="hello2"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello3" Value="hello3"></telerik:RadTreeNode><br>                                    </Nodes><br>                                </telerik:RadTreeView>


in code behind:
i also checked but its not working

RadTreeView1.ClearCheckedNodes();<br>RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text=="hello1").FirstOrDefault();<br>                trnode.Selected = true;<br>               // trnode.Checkable = true;<br>                trnode.Checked = true;


i want to check only parent while binding the data

can anyone please help to tell me if i am doing something wrong, it is not possible or some kind of bug

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 May 2012, 08:05 AM
Hi Karamjeet,

Parent node in a RadTreeView with TriStateCheckBoxes checks only when the child nodes are checked. Please try setting TriStateCheckBoxes property of RadTreeView to false to check only the parent node while binding data as follows.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" TriStateCheckBoxes="false" CheckBoxes="true" CheckChildNodes="false">
  <Nodes>
     <telerik:RadTreeNode Text="hello" Value="hello">
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true">
        <Nodes>
          <telerik:RadTreeNode Text="hello11" Value="hello11">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello12" Value="hello12">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello13" Value="hello13">
          </telerik:RadTreeNode>
       </Nodes>
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="hello2" Value="hello2">
      </telerik:RadTreeNode>
      <telerik:RadTreeNode Text="hello3" Value="hello3">
      </telerik:RadTreeNode>
  </Nodes>
</telerik:RadTreeView>

C#:
RadTreeView1.UncheckAllNodes();
RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text == "hello1").FirstOrDefault();
trnode.Selected = true;
trnode.Checked = true;

Hope this helps.

Thanks,
Princy.
0
karamjeet
Top achievements
Rank 1
answered on 08 May 2012, 10:46 AM
ok Thanks for your quick response

But i also want that if someone check child node, parent should be checked
which on checking the child working perfect but after when i disable tristate it will no longer check the parent

Any workaround on this.


And thanks for your quick response.
0
Princy
Top achievements
Rank 2
answered on 09 May 2012, 05:32 AM
Hi Karamjeet,

Here is the sample code snippet that i tried to achieve your scenario.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" TriStateCheckBoxes="false" CheckBoxes="true"  OnClientNodeChecked="OnClientNodeChecked" CheckChildNodes="false">
  <Nodes>
     <telerik:RadTreeNode Text="hello" Value="hello">
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true">
        <Nodes>
          <telerik:RadTreeNode Text="hello11" Value="hello11">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello12" Value="hello12">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello13" Value="hello13">
          </telerik:RadTreeNode>
       </Nodes>
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="hello2" Value="hello2">
      </telerik:RadTreeNode>
      <telerik:RadTreeNode Text="hello3" Value="hello3">
      </telerik:RadTreeNode>
  </Nodes>
</telerik:RadTreeView>

JS:
<script type="text/javascript">
    function OnClientNodeChecked(sender, args)
    {
        if (args.get_node().get_level() != 0)
        {
            args.get_node().get_parent().check();
        }
    }
</script>

C#:
protected void Page_Load(object sender, EventArgs e)
    {
        RadTreeView1.UncheckAllNodes();
        RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text == "hello1").FirstOrDefault();
        trnode.Selected = true;
        trnode.Checked = true;
    }

Hope this helps.

Thanks,
Princy.
Tags
TreeView
Asked by
karamjeet
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
karamjeet
Top achievements
Rank 1
Share this question
or