Disable selection for certain items in Dropdown Tree

Is it possible to disable the selection of certain items in the dropdown tree list?


I have a dropdown tree showing up to 3 tiers of the hierarchy, and I want to set it so that you can't select the expanding options, so the user can only select the "bottom level" of options. Basically I want to use the expanding options as "section headings" for the selectable bottom-level children in the list. Like using the tree-view component within a dropdown


In the demo for the component, it would be like disabling the ability to select "North America" from the list, but allow United States, Mexico, and Cuba to be selected.


1 Reply 1 reply marked as answer

LD LeoLavanya Dhanaraj Syncfusion Team April 26, 2024 11:24 AM UTC

Hi Josiah,


Greetings from Syncfusion support.


From your shared details, we understand that you want to disable the selection of a parent tree node in the Dropdown Tree component(not to select but need to perform the expand/collapse action). You can meet your requirement by canceling the selection of the parent tree node. This can be achieved by checking whether the selected node has children or not inside the ValueChanging event.


For your reference, we have included the Dropdown Tree sample and code snippets.


Sample : https://blazorplayground.syncfusion.com/VZVJXJhdfZWckhyE


<SfDropDownTree TValue="string" ID="hierarchical" ValueChanging="OnValueChanging"> …

</SfDropDownTree>

 

private void OnValueChanging(DdtChangeEventArgs<string> args)

{

    if (args.NodeData.HasChildren)

    {

        args.Cancel = true;

    }

}


Please get back to us if you need any further assistance.


Regards,

Leo Lavanya Dhanaraj


Marked as answer
Loader.
Up arrow icon