I have a datagrid where allowMutipleSelection is true. I'm trying to
disallow selection of certain rows in the grid. I tried hooking into
the ListEvent.CHANGE event and removing disallowed items from the
selectedItems array:

    addEventListener(ListEvent.CHANGE, selectionChangeHandler);

    private function selectionChangeHandler(event:ListEvent):void
    {
        var items:Array = new Array();
        for each (var item:Object in selectedItems)
        {
            if (itemIsSelectable(item))
                items.push(item);
        }
        selectedItems = items;
    }

    private function itemIsSelectable(item:Object):Boolean
    {
        // determine whether item is selectable...
        :
    }

This works fine for single-click and ctrl-click selection, but somehow
the very existence of code inside selectionChangeHandler breaks
shift-click selection. What I mean is that if I include the code
above, then if you try to multi-select via shift-click, by the time
you get into selectionChangeHandler, selectedItems contains only a
single item (the starting item). This is before my code has even run!
Yet if you comment out the code inside the handler, shift-click works
normally. 

I *think* this looks like a timing issue since if I run in debug mode
and single-step all the way through mouseDownHandler (all the way up
the superclass chain to ListBase), then shift-click is okay.

Does anyone have any ideas on how I can make this work? Or
alternatively, another way to disallow selection of particular items?

Thanks!

Reply via email to