3 Replies Latest reply on Aug 31, 2010 11:37 PM by Vikash.kumar29

    How do I prevent a record from being copied?

    SiHoop Level 1

      The following code creates a datagrid. Records in the datagrid can be moved via click and drag. But the record is copied if the user presses the control key while dragging a record.

      How can I prevent the copy from occurring?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="init()">
          <mx:Script>
              <![CDATA[
      [Bindable] private var myXml:XML
      private function init():void{
             
          myXml=
              <TABLE>
                 <EXAMPLE>
                    <difficulty> 0.8152</difficulty>
                    <discrimination> 0.4259</discrimination>
                    <item> 2 </item>
                 </EXAMPLE>
                 <EXAMPLE>
                    <difficulty> 0.8641 </difficulty>
                    <discrimination> 0.3707</discrimination>
                    <item> 4 </item>
                 </EXAMPLE>
                 <EXAMPLE>
                    <difficulty> 0.5706 </difficulty>
                    <discrimination> 0.2631</discrimination>
                    <item> 6 </item>
                 </EXAMPLE>
              </TABLE>   
             
          }
              ]]>
          </mx:Script>

       


          <mx:DataGrid x="500" y="200" dataProvider="{myXml.EXAMPLE}" width="200" height="300"  dragEnabled="true"  dragMoveEnabled="true" dropEnabled="true" >
              <mx:columns>
                  <mx:DataGridColumn headerText="Item" dataField="item"/>
                  <mx:DataGridColumn headerText="Discrimination index" dataField="discrimination"/>
                  <mx:DataGridColumn headerText="Difficulty" dataField="difficulty"/>
              </mx:columns>
          </mx:DataGrid>
      </mx:Application>

        • 1. Re: How do I prevent a record from being copied?
          Subeesh Arakkan Level 4

          Hi,

           

          Listen for the drag drop event and change the action from copy to move on the fly.

           

          <mx:DataGrid x="500" y="200" dataProvider="{myXml.EXAMPLE}" width="200" height="300"  
                    dragEnabled="true"  dragMoveEnabled="true" dropEnabled="true" 
                    dragDrop="datagrid_dragDropHandler(event)">
          

           

           

          private function datagrid_dragDropHandler(event:DragEvent):void
          {
               if(event.action == "copy")
                    event.action = "move";
          }
          
          • 2. Re: How do I prevent a record from being copied?
            SiHoop Level 1

            This works perfectly-- thank you!

             

            However, if the control key is pressed during a drag-drop, the cursor changes to show a small green +-sign. How can I prevent this from happening? What is the property that is set to change the cursor?

            • 3. Re: How do I prevent a record from being copied?
              Vikash.kumar29 Level 3

              add an event listner for dragStart,dragEnter and  dragOver on the dataGrid like :

               

              <mx:DataGrid x="500" y="200" dataProvider="{myXml.EXAMPLE}" width="200" height="300"            dragEnabled="true"  dragMoveEnabled="true" dropEnabled="true"           dragDrop="datagrid_dragDropHandler(event)" dragOver="checkDragHandler(event)" dragStart="checkDragHandler(event)" dragEnter="checkDragHandler(event)">

               

              and handler as :

               

              protected function checkDragHandler(event:DragEvent):void
              {
                   if(event.ctrlKey)
                   event.ctrlKey = false;
              }
              

               


              This do help me. Hopes also works for you.

               

              -Vikash

              1 person found this helpful