Preventing specific items from being selected in a flex tree control

Source: Internet
Author: User

The following example shows you how you can preventAnyItem from being selected by adding an attribute (named "clickable", but you cocould name it anything you wanted) and using E4X expressions to determine if the currently clicked item shocould be selectable or not.

Full code after the jump.

 

Note that in the following example, items with the "(x)" suffix are not-selectable, only the following nodes shocould be selectable: "grandchild 1", "grandchild 2 ″, and "child 4 ″.

<? XML version = "1.0" encoding = "UTF-8" ?>
<! -- Http://blog.flexexamples.com/2008/01/16/preventing-specific-items-from-being-selected-in-a-flex-tree-control/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "Middle"
Backgroundcolor = "White"
Creationcomplete = "Init ();" >

<MX: script>
<! [CDATA [
Import MX. Events. listevent;

Private function Init (): void {
Tree. openitems = DP... node;
}

Private function tree_itemclick (EVT: listevent): void {
VaR item: Object = EVT. currenttarget. selecteditem;
VaR nonselectable: Boolean = (item. hasownproperty ("@ clickable") & (item. (@ clickable = "false ")));
If (nonselectable ){
Tree. selecteditem = NULL;
}
}
]>
</ MX: script >

< MX: XML ID = "DP" >
< Root >
< Node Label = "Parent 1 (x )" Clickable = "False" >
< Node Label = "CHILD 1 (x )" Clickable = "False"   />
< Node Label = "Child 2 (x )" Clickable = "False" >
< Node Label = "Grandchild 1"   />
< Node Label = "Grandchild 2"   />
</ Node >
< Node Label = "Child 3 (x )" Clickable = "False"   />
< Node Label = "Child 4"   />
</ Node >
</ Root >
</ MX: XML >

< MX: Tree ID = "Tree"
Dataprovider = "{DP }"
Showroot = "False"
Labelfield = "@ Label"
Width = "200"
Itemclick = "Tree_itemclick (event );"   />

</MX: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.