In a previous example, “Disabling keyboard navigation on the Accordion container in Flex”, we saw how to disabe keyboard navigation on the Flex Accordion container by overriding the keyDownHandler() method.

The following example shows how you can disable keyboard navigation on the Flex List control by extending the List class and overriding the protected keyDownHandler() method.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/11/disabling-keyboard-navigation-on-the-list-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        xmlns:comps="comps.*"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
        <mx:Object label="Seven" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
    </mx:Array>

    <comps:MyList id="list"
            dataProvider="{arr}"
            width="100" />

</mx:Application>

comps/MyList.as

/**
 * http://blog.flexexamples.com/2008/06/11/disabling-keyboard-navigation-on-the-list-control-in-flex/
 */
package comps {
    import flash.events.KeyboardEvent;
    import mx.controls.List;

    public class MyList extends List {
        public function MyList() {
            super();
        }

        override protected function keyDownHandler(event:KeyboardEvent):void {
        }
    }
}

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

6 Responses to Disabling keyboard navigation on the List control in Flex

  1. 小小菜鸟 says:

    thanks for you tutorials~ very userful!@

  2. Thank you for your tutorials.

    It’s possible to set a handCursor to a DataGrid Control?

    I mean not only the Headers but the list too, preserving the list properties like the roll over and the selected Item color while using the hand cursor on the rows.

    Thank you for your time.

  3. Krishna says:

    Thank you for your tutorial.

    Here I have one requirement i.e. I need to disable alt key and their combinations like f4, tab and also Esc key. I am implementing flex application as Desktop Application (runs in AIR).

    Please tell me how can I disable these keys.

    Regards,
    Krishna

  4. Gabor says:

    Hi Peter,
    thanks a lot for this example.

    Unfortunatly when I try to use a TileLayout in my CustomList I get the following Error: Could not resolve <s:layout> to a component implementation.

    I’m a bit confused about the Namespaces here…

    • Gabor says:

      Just found the Namespace solution.

      Use the same Namespace for the <components:layout> tag as for your custom component.

  5. Capotudo says:

    How can I override the enter key behavior on a Datagrid? I’m assuming there like a enterHandler() method I can override, but can’t find any documentation on it.

    Thanks!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree