DropDownTree Set Selectable Property

5 posts, 0 answers
  1. Angie
    Angie avatar
    120 posts
    Member since:
    Jan 2008

    Posted 23 Nov 2020 Link to this post

    I am using the DropDownTree to display nested items. Sometimes parents are selectable, sometimes they are not.

    In the dataset being returned, I have 3 columns:  Text, Value, IsSelectable.

    Is there a way to pass the IsSelectable property through to the DropDownTree and then make the items selectable based on that property?  It seems like it only takes Value and Text.  

    Please let me know if there is a way for this to work!  Thank you!
  2. Peter Milchev
    Admin
    Peter Milchev avatar
    895 posts

    Posted 27 Nov 2020 Link to this post

    Hello Angie,

    You can try subscribing to the NodeDataBound event of the EmbeddedTree where you can access the data for each item and decide which properties to set:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadDropDownTree1.DataFieldID = "ID";
            RadDropDownTree1.DataFieldParentID = "ParentID";
            RadDropDownTree1.DataValueField = "Value";
            RadDropDownTree1.DataTextField = "Text";
            RadDropDownTree1.EmbeddedTree.NodeDataBound += EmbeddedTree_NodeDataBound;
            RadDropDownTree1.DataSource = GetData();
            RadDropDownTree1.DataBind();
        }
    }
    
    private void EmbeddedTree_NodeDataBound(object sender, RadTreeNodeEventArgs e)
    {
         // decide which Node properties to set
    }

    Regards,
    Peter Milchev
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Angie
    Angie avatar
    120 posts
    Member since:
    Jan 2008

    Posted 30 Nov 2020 in reply to Peter Milchev Link to this post

    Hi Peter, thank you for the reply.  I also found your reply in this link: https://www.telerik.com/forums/hide-disable-node.

    In your above example, the right side of RadDropDownTree1.EmbeddedTree.NodeDataBound += EmbeddedTree_NodeDataBound does not resolve for me. See attached image.

    So instead, I tried using the available events from https://docs.telerik.com/devtools/aspnet-ajax/controls/treeview/server-side-programming/events/nodedatabound, but the "enabled" property is not available.  I tried using the "checkable" property instead, even though I am not using checkboxes.

    protected void ddtForums_NodeDataBound(object sender, DropDownTreeNodeDataBoundEventArguments e)
            {
                e.DropDownTreeNode.Checkable = false;  //this is just for testing
            }

     

    It does prevent the item from being selected, however the client events OnClientEntryAdded and OnClientEntryAdding still fire.  I would expect the OnClientEntryAdded not to be fired, since it's not being added to the entries.

    In order to handle the client event firing, I would need to know how to detect if the node is disabled in javascript.

    function ForumChanged(sender, args) {
            if (--node not enabled - WHAT IS NEEDED HERE--)
                return;
            //check location if needed
            var value = args.get_entry().get_value();
        }

     

    Thank you!

     

  4. Angie
    Angie avatar
    120 posts
    Member since:
    Jan 2008

    Posted 01 Dec 2020 in reply to Angie Link to this post

    Hi!  An additional to this post, I'm realizing that with e.DropDownTreeNode.Checkable = false;, the nodes are stilll being selected, I just thought they weren't because the drop down does not close.  So it makes sense that the client events are still firing.  So I still need assistance with the code to prevent the nodes from being selectable.  Thank you!
  5. Peter Milchev
    Admin
    Peter Milchev avatar
    895 posts

    Posted 03 Dec 2020 Link to this post

    Hello Angie,

    Once you add the RadDropDownTree1.EmbeddedTree.NodeDataBound += EmbeddedTree_NodeDataBound, you need to have a method with the same name and the correct arguments:

    private void EmbeddedTree_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
    {
        // use data item data instead
        if (e.Node.Text == "World Continents")
        {
            e.Node.Enabled = false;
        }
    }

    Also, you can add use Visual Studio to generate the handler for you by typing  RadDropDownTree1.EmbeddedTree.NodeDataBound += and then press the TAB key twice.

    The link that you have shared is actually showing the TreeView control's events, but the snippet below it is actually the one for the DropDownTree, not the TreeView:

    protected void ddtForums_NodeDataBound(object sender, DropDownTreeNodeDataBoundEventArguments e)

    The DropDownTreeNode, unfortunately, does not have all the properties of the TreeView's RadTreeNode. That is why the TreeView's NodeDataBound is needed. 

    Regarding the Checkable property, it controls the checkbox of the node when the checkboxes are enabled for the DropDownTree. If you want to control if the node can be selected, you need to use the Enabled property of the TreeView node, not the DropDownTree's:

    Once the TreeView's node is disabled, it will not be selectable. 

    Regards,
    Peter Milchev
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top