Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:26:45+00:00 2026-05-14T03:26:45+00:00

how would you prevent dragging for some items of your List or DataGrid? Let’s

  • 0

how would you prevent dragging for some items of your List or DataGrid?

Let’s say I had a list with two items: ‘Tom’ and ‘Jerry’. Only ‘Tom’ should be dragable, not ‘Jerry’.

Ideally I had a ‘isDragEnabled(item:Object):Boolean’ function, which is being queried by the drag source.

My difficulties start with the fact that the ‘dragStart’ event handler has a null value for the dragSource, so right from the start I find it hard to find out what the drag-start is about..

Thanks in advance!

PS There have been a few discussions on preventing or canceling a drop, but I haven’t seen much about preventing the drag start, hence this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:26:46+00:00Added an answer on May 14, 2026 at 3:26 am

    Ok, got it, thanks Robusto, your tip #2 was the inspiration, however I had to use a mouse-down listener — the selection event fires too late.

    In the sample all below I am using code from some other question of mine.

    This sample lets you drag only the first item in the List or DataGrid:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" minWidth="955" minHeight="600">
    
        <mx:List id="list" dataProvider="{['Tom','Jerry', 'Amy', 'Betty', 'Chris', 'Dean', 'Email', 'Floyd', 'Grant', 'Helen', 'Iris', 'Jack']}" minWidth="200"
            mouseDown="onMouseDown(event)"
            />
    
        <mx:DataGrid id="dg" dataProvider="{[{title:'Tom'},{title:'Jerry'}]}" minWidth="200"
             mouseDown="onMouseDown(event)" 
        >
            <mx:columns>
                <mx:DataGridColumn dataField="title" />
            </mx:columns>
        </mx:DataGrid>
    
        <mx:Script>
            <![CDATA[
                import mx.controls.listClasses.ListBase;
                import mx.events.DragEvent;
    
    
                protected function onMouseDown(event:MouseEvent):void
                {
                    var listBaseComp:ListBase = ListBase(event.currentTarget);
                    var clickIndex:int = this.findClickedItemIndex(event.stageX, event.stageY, listBaseComp);
                    listBaseComp.dragEnabled = clickIndex == 0;
                }
    
                /**
                 * Returns a dataProvider item that displays at the given coords for the given dataGrid.
                 * Code provided by Stackoverflow user https://stackoverflow.com/users/165297/amarghosh,
                 * thanks a lot!
                 */
                protected function findClickedItemIndex(globalX:Number, globalY:Number, listComp:ListBase):int
                {
                    var p1 : Point;
                    var p2 : Point;
                    var renderer : DisplayObject;
    
                    for(var i:int=0; i<listComp.dataProvider.length; i++) {
                        renderer = DisplayObject(listComp.indexToItemRenderer(i));
                        if (!renderer) //item is not displayed (scroll to view it)
                            continue;
                        p1 = new Point(renderer.x, renderer.y);
                        p2 = new Point(renderer.width, renderer.height);
                        p1 = renderer.parent.localToGlobal(p1);
                        p2 = renderer.localToGlobal(p2);
                        if(globalX >= p1.x && globalX <= p2.x && globalY >= p1.y && globalY <= p2.y)
                            return i;
                    }   
                    return -1;
                }
    
            ]]>
        </mx:Script>
    </mx:Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought by placing these two lines that it would prevent the page from
Are there any compatibility issues that would prevent this from working? Do I need
Does cygwin allow a statically compiled binary? This would prevent the need for cygwin1.dll
I am using an ASP.NET ModalPopupExtender on a page and would like to prevent
I would like to either prevent or handle a StackOverflowException that I am getting
I thought that it would be fun to present some classic CS problems and
Is there some way to (temporarily) prevent user from changing the value of TrackBar
I have a ListView-like control that displays a list of items of various heights.
What conditions would prevent the JVM from running a FULL Garbage Collection when the
It seems that licensing terms would prevent us from using Google Maps API in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.