• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

drag and drop datagrid

Hello I wonder if I can click on a column of
datagrid and drag it to another datagrid datagrid but I second that
I want to fill in the name of the column and not its contents
0
eduardo12fox
Asked:
eduardo12fox
  • 4
  • 3
1 Solution
 
Pravin AsarCommented:
With a datagrid event (such as drag and drop), you can access the property "datafield" to get which column was selected.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/events/DataGridEvent.html

And if you want to target drid to have only "datafield"[column name] and not the contents of source datagrid .


Implement you dragdropHandler Function.

add this as first line in the dragdragHandler.

event.preventDefault(); // This will prevent the default action  
0
 
eduardo12foxAuthor Commented:
I need to drag a column of the grid second place on the main grid and
by clicking the "DISABLED COLUMN SELECTED" column that is disabled
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  <mx:Script>
    <![CDATA[
    	import mx.containers.Grid;
    	import mx.controls.Alert;
    	import mx.controls.dataGridClasses.DataGridColumn;
      	import mx.collections.ArrayCollection;
      	import mx.controls.DataGrid;
      	import mx.events.DragEvent;
      	import mx.managers.DragManager;
      
      
	      private function dragCompleteHandler(event:DragEvent):void {
	      	
	        if(event.action != DragManager.NONE) {
	          var grid:DataGrid = DataGrid(event.dragInitiator);
	          var data:ArrayCollection = ArrayCollection(grid.dataProvider);
	          var item:Object = event.dragSource.dataForFormat("items")[0];
	          for(var i:uint = 0; i < data.length; i++) {
	            if(data.getItemAt(i).emailId == item.emailId) {
	              data.removeItemAt(i);
	              break;
	            }
	          }
	        }
	      }
	        
	 
	      
	      private function DisableColumn():void{
	      
	      		
	      
	      }

  ]]>
  </mx:Script>
  <mx:XMLList id="employees">
        <employee>
            <name>Christina Coenraets</name>
            <phone>555-219-2270</phone>
            <email>ccoenraets@fictitious.com</email>
            <active>true</active>
            <image>images/arrow_icon_sm.png</image>
        </employee>
        <employee>
            <name>Joanne Wall</name>
            <phone>555-219-2012</phone>
            <email>jwall@fictitious.com</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Maurice Smith</name>
            <phone>555-219-2012</phone>
            <email>maurice@fictitious.com</email>
            <active>false</active>
        </employee>
        <employee>
            <name>Mary Jones</name>
            <phone>555-219-2000</phone>
            <email>mjones@fictitious.com</email>
            <active>true</active>
        </employee>
    </mx:XMLList>
      <mx:DataGrid dropEnabled="true" dataProvider="{employees}" dragEnabled="true" dragComplete="dragCompleteHandler(event)" id="grid" y="164" horizontalCenter="0">
        <mx:columns>
          <mx:DataGridColumn headerText="COL1" dataField="name"/>
          <mx:DataGridColumn headerText="COL2" dataField="phone"/>
          <mx:DataGridColumn headerText="COL3" dataField="email"/>
          <mx:DataGridColumn headerText="COL4" dataField="active"/>
          <mx:DataGridColumn headerText="COL5" dataField="image"/>
        </mx:columns>
      </mx:DataGrid>
      <mx:DataGrid dropEnabled="true" dragEnabled="true" dragComplete="dragCompleteHandler(event)" y="376" horizontalCenter="0">
        <mx:columns>
          <mx:DataGridColumn headerText="COLUNA" dataField="name"/>
        </mx:columns>
      </mx:DataGrid>
      <mx:Button label="DISABLED COLUMN SELECTED" color="#000000" click="{DisableColumn()}" y="550" horizontalCenter="0"/>
</mx:Application>

Open in new window

0
 
Pravin AsarCommented:
Here is simple example of dragdrop to capture columnname.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
            <![CDATA[
                  import mx.controls.dataGridClasses.DataGridColumn;
                  import mx.events.DragEvent;
                  public var srcX:int;
                  [Bindable] public var trgData:ArrayCollection = new ArrayCollection();
                  public function srcMouseHandler(evt:MouseEvent):void {
                        var pt:Point = new Point(evt.localX, evt.localY);
                        var dg:DataGrid =evt.currentTarget as DataGrid;
                        var gpt:Point = srcGrid.localToGlobal(pt);
                        srcX=mouseX;
                  }
                  public function trgDragDropHandler(evt:DragEvent):void {
                        evt.preventDefault();
                        var srcGrid:DataGrid = evt.dragInitiator as DataGrid;
                        var column:DataGridColumn = getDataGridColumn(srcX,srcGrid);
                        if (column) {
                              var data:Object = new Object();
                              data.selectedColumn= column.dataField.toString();
                              trgData.addItem(data);
                        }
                  }
                  public function getDataGridColumn(posX:int, dg:DataGrid):DataGridColumn {
                        var dgc:DataGridColumn = null;
                        var pt:Point = new Point(dg.x, dg.y);
                        var gpt:Point = dg.localToGlobal(pt);
                        var dgcX:int=gpt.x;
                        for (var cx:int=0; cx < dg.columns.length; cx++) {
                              dgc=dg.columns[cx] as DataGridColumn;
                              dgcX += dgc.width;
                              if (dgcX > posX) { return dgc; }
                        }
                        return null;
                  }
            ]]>
      </mx:Script>
      <mx:ArrayCollection id="srcData">
            <mx:source>
                  <mx:Object col1="Row 1 Col1" col2="Row 1 Col2" col3="Row 1 Col 3"/>
                  <mx:Object col1="Row 2 Col1" col2="Row 2 Col2" col3="Row 2 Col 3"/>
                  <mx:Object col1="Row 3 Col1" col2="Row 3 Col2" col3="Row 3 Col 3"/>
                  <mx:Object col1="Row 4 Col1" col2="Row 4 Col2" col3="Row 4 Col 3"/>
                  <mx:Object col1="Row 5 Col1" col2="Row 5 Col2" col3="Row 5 Col 3"/>
            </mx:source>
      </mx:ArrayCollection>
      <mx:HDividedBox x="100" y="100" width="100%" height="100%">
            <mx:DataGrid id="srcGrid" dragEnabled="true" width="75%" height="100%" dataProvider="{srcData}" mouseDown="srcMouseHandler(event);">
                  <mx:columns>
                        <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                        <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                        <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
                  </mx:columns>
            </mx:DataGrid>
            <mx:DataGrid id="trgGrid" dropEnabled="true" width="25%" height="100%" dataProvider="{trgData}" dragDrop="trgDragDropHandler(event);">
                  <mx:columns>
                        <mx:DataGridColumn headerText="Selected Column" dataField="selectedColumn"/>
                  </mx:columns>
            </mx:DataGrid>
      </mx:HDividedBox>
      
</mx:Application>
0
Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

 
Pravin AsarCommented:
Take this one... Handles invisible /hidden columns from srcGrid


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
            <![CDATA[
                  import mx.controls.dataGridClasses.DataGridColumn;
                  import mx.events.DragEvent;
                  public var srcX:int;
                  [Bindable] public var trgData:ArrayCollection = new ArrayCollection();
                  public function srcMouseHandler(evt:MouseEvent):void {
                        
                        srcX=mouseX;
                  }
                  public function trgDragDropHandler(evt:DragEvent):void {
                        evt.preventDefault();
                        var srcGrid:DataGrid = evt.dragInitiator as DataGrid;
                        var column:DataGridColumn = getDataGridColumn(srcX,srcGrid);
                        if (column) {
                              var data:Object = new Object();
                              data.selectedColumn= column.dataField.toString();
                              trgData.addItem(data);
                        }
                  }
                  public function getDataGridColumn(posX:int, dg:DataGrid):DataGridColumn {
                        var dgc:DataGridColumn = null;
                        var pt:Point = new Point(dg.x, dg.y);
                        var gpt:Point = dg.localToGlobal(pt);
                        var dgcX:int=gpt.x;
                        for (var cx:int=0; cx < dg.columns.length; cx++) {
                              dgc=dg.columns[cx] as DataGridColumn;
                              // Handle invisible columns
                              if (!dgc.visible) { continue; }
                              dgcX += dgc.width;
                              if (dgcX > posX) { return dgc; }
                        }
                        return null;
                  }
            ]]>
      </mx:Script>
      <mx:ArrayCollection id="srcData">
            <mx:source>
                  <mx:Object col1="Row 1 Col1" col2="Row 1 Col2" col3="Row 1 Col 3"  col4="Row 1 Col 4"/>
                  <mx:Object col1="Row 2 Col1" col2="Row 2 Col2" col3="Row 2 Col 3"  col4="Row 2 Col 4"/>
                  <mx:Object col1="Row 3 Col1" col2="Row 3 Col2" col3="Row 3 Col 3"  col4="Row 3 Col 4"/>
                  <mx:Object col1="Row 4 Col1" col2="Row 4 Col2" col3="Row 4 Col 3"  col4="Row 4 Col 4"/>
                  <mx:Object col1="Row 5 Col1" col2="Row 5 Col2" col3="Row 5 Col 3"  col4="Row 5 Col 4"/>
            </mx:source>
      </mx:ArrayCollection>
      <mx:HDividedBox x="100" y="100" width="75%" height="75%">
            <mx:DataGrid id="srcGrid" dragEnabled="true" width="75%" height="100%" dataProvider="{srcData}" mouseDown="srcMouseHandler(event);">
                  <mx:columns>
                        <mx:DataGridColumn headerText="Column 1" dataField="col1" visible="false"/>
                        <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                        <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
                        <mx:DataGridColumn headerText="Column 4" dataField="col4"/>
                  </mx:columns>
            </mx:DataGrid>
            <mx:DataGrid id="trgGrid" dropEnabled="true" width="25%" height="100%" dataProvider="{trgData}" dragDrop="trgDragDropHandler(event);">
                  <mx:columns>
                        <mx:DataGridColumn headerText="Selected Column" dataField="selectedColumn"/>
                  </mx:columns>
            </mx:DataGrid>
      </mx:HDividedBox>
      
</mx:Application>
0
 
eduardo12foxAuthor Commented:
I have no words to thank, it was PERFECT !!!!! Just as I wanted very, very, very
Thank you thank you it was fantastic.

Thank,Thank,ThankThank HJuahauhhahha!!! KKKKKK
0
 
eduardo12foxAuthor Commented:
It was perfect the way I wanted to note was 1000
0
 
Pravin AsarCommented:
Glad this worked for you.


Thanks
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now