7/6/2010 10:26:45 AM
Title:
get Corresponding column value Datagrid
I have a datagrid with some columns and a button placed inside the datagrid on each row.
My problem is I want to get any correponding column value by clicking on its corresponding button.Pls help.
7/6/2010 10:43:16 AM
on click of button you an get the index value of the row of DataGrid. Know use that index value to get data of any column at that position from the dataProvider. i.e
mydataProvider[index].name
7/6/2010 10:52:16 AM
check this example
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.controls.DataGrid;
private var xml:XML = <root>
<item>one</item>
<item>two</item>
<item>three</item>
</root>;
[Bindable] private var myDataProvider:XMLListCollection = new
XMLListCollection(xml..item);
public function changeText(event:MouseEvent):void{
//traced the item in row of button clicked
trace(myDataProvider.getItemAt(myDataGrid.selectedIndex));
}
]]>
</mx:Script>
<mx:DataGrid id="myDataGrid" dataProvider="{myDataProvider}">
<mx:columns>
<mx:DataGridColumn headerText="String Text"
dataField="item">
<mx:itemRenderer>
<mx:Component>
<mx:Text text="{data}"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="CheckBox">
<mx:itemRenderer>
<mx:Component>
<mx:Button label="Get Item"
click="outerDocument.changeText(event)"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>