Hi,

Do you mean, when focus goes to a cell in an editable DataGrid, you want to
do some validation/formatting based of the content there?

You can probably look at cellFocusIn & cellFocusOut events of DataGrid,
these are broadcast when a cell gets focus & loses focus respectively. You
can write your logic in their handlers...

Details:

cellFocusIn/cellFocusOut's event object contains following properties....

- itemIndex Index of the selected item.
- columnIndex Index of the selected column.
- target Reference to the component that triggered the event.
- type Name of the event. 



I have made a simple sample, might be useful for you...Following example
shows how you can retrieve data from a focussed cell and how can you modifiy
cell data when focus is lost...


##DataGridCellFocusTest.mxml###

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
backgroundColor="#FFFFFF">

<mx:Script>
<![CDATA[

function handleCellFocus(event)
{

var target = event.target;
var index = event.itemIndex;
var colIndex = event.columnIndex;
var col = target.getColumnAt(colIndex);
var item = target.getItemAt(index);
var colName = col.columnName;

debug_ta.text += "Text in Current Cell: " +
(item[col.columnName]) + "\n";



}

function handleCellFocuOut(event)
{
var target = event.target;

var target = event.target;
var index = event.itemIndex;
var colIndex = event.columnIndex;
var col = target.getColumnAt(colIndex);
var item = target.getItemAt(index);
var colName = col.columnName;


target.editField(index, col.columnName,
Math.random()*1000);
debug_ta.text += "Previous Cell data changed to
random num: " + (item[col.columnName]) + "\n";

}
]]>
</mx:Script>

<mx:Panel title="DataGrid Panel" marginTop="10">

<mx:VBox>

<mx:DataGrid id="myGrid" width="350" height="100"
cellFocusIn="handleCellFocus(event)" cellFocusOut="handleCellFocuOut(event)"
editable="true">

<mx:dataProvider>
<mx:Array id="arr">
<mx:Object Artist=" Kapil" Album="All Time
Favourites" Price="10"/> 
<mx:Object Artist=" Kapil" Album="Classic Songs"
Price="10"/>
</mx:Array>
</mx:dataProvider>

</mx:DataGrid>

</mx:VBox>

<mx:TextArea id="debug_ta" text="" width="300%" height="200"/>

</mx:Panel>

</mx:Application> 


-abdul




-----Original Message-----
From: valysivec27 [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 17, 2005 7:07 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] editable datagrid



Hi All,

How do I change/replace the content of a cell in an editable data 
grid when the cell gets focus (depending on the current content). Is 
there an easy way to do that ?

Thanks,
Val.







Yahoo! Groups Links









Reply via email to