views:

566

answers:

3

Hi,

I have a datagrid with custom itemRenderer. When I click in a cell, I get its reference. Now I would like to get the reference of the other column in the sae row. e.g. In the datagrid I have clicked in 4th column of the 3rd row, I am getting reference of it no problem in that. Now I would like to get the reference of 1st column of the same row i.e 3rd.

Is there a way?

Thanks.

A: 

Your custom item renderers should be data driven. In other words everything you care about should be on the renderer's "data" property. If you need to manipulate another cell, you should manipulate the data for the row, and the cell should update itself.

That's the reason you're having a hard time with that -- there isn't a good way to grab a reference to another cell. There are bad ways, but they're bad :)

Sean Clark Hess
A: 

don't know if I understand this completely correct but here goes...

put on your datagrid a click event

<mx:DataGrid id="myDatagrid" click="getValues()" dataProvider="{someArrayColl}"/>

let say the first column has the name: 'id_column' between the script lines:

private function getValues():void{
var first_column_value:String = myDatagrid.selectedItem.id_column;

//if you want the entire row in 1 Array
var the_selected_row:Array = myDatagrid.selectedItem as Array;
}

haven't tested the array statement but it should work. myDatagrid.selectedItem is default an object of an arraycollection.

//you should put a try and catch statement in the getValues function to catch the exception when users click on a headeritem or the datagrid-scrollbar

Jozzeh
A: 

Sean, can you please enumerate the bad ways? Thanks...

Yarin