Making the Datagrid dragable

Currently I am building custom components which contain the DataGrid component.
When a datagrid row is selected the cellPress-event is fired. In the method handling this event a dragaction is initiated handled by a Singleton-class the DragManager.
The problem: when the mouse is pressed and you roll over other rows the rows get a rollOver and get highlighted instead of leaving the row which content is dragged stays highlighted.
My solution is overwriting the onRowPress method of the datagrid:

import mx.controls.DataGrid;
private var grid:DataGrid;
this.grid.onRowPress = function(rowIndex:Number){
	if (!this.enabled) return;
	var len : Number = this.columns.length;
	var row = this.rows[rowIndex];
	// fire cellPress event
	for (var i=0; i<len ; i++) {
		var col : mx.controls.gridclasses.DataGridColumn = this.columns[i];
		var delta : Number = row._xmouse - row.cells[i]._x;
		if (delta>=0 && delta<col .__width) {
			this.dispatchEvent({type:"cellPress", columnIndex: i, view: this, itemIndex: rowIndex + this.__vPosition});

The changes to the original method is that the super.onRowPress isn’t called and a few “this.” had to be added. I know that this is not beautiful solution but it works. Another possibility would be subclassing the datagrid e.g. DragableDataGrid. Until now I like the quick and dirty solution.

2 comments to Making the Datagrid dragable

  • Larry


    You seem to have a lot of knowledge about flex 2 and datagrid. I was wondering if you could answer a question for me? I have an application where the user needs to start out with an empty datagrid and then enter the data into each column of the grid at the end of the first row droping down to the next row to continue entering new data in the grid then on to maybe the 3rd,4th,5th… etc until all of the data have been entered I hope I made myself clear. We are a clothing manufacture and have columns for fabric,style,color,cost,xs,s,m,l,xl,subtotal total extended for each row can the flex 2 data grid do this or is only for loading data from the database?

    Thank you for any help

    Larry Abbott

  • Sönke

    Hi Larry,

    the post you commented was not flex 2 yet.
    Anyway I understand your problem but I don’t have a solution for you. I would recommend you post your problem to the flexcoders mailinglist and I am sure you will get help there.