Classic recycling issues.  Read my blog for more info.  You must have code that 
also sets enabled=true somewhere.

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of 
jackoo.zhang
Sent: Tuesday, September 16, 2008 12:53 AM
To: [email protected]
Subject: [flexcoders] when click sort on datagrid column, more than one cell 
have been disabled.


Hi,
I try to modify second example from
http://livedocs.adobe.com/flex/3/html/help.html?
content=cellrenderer_4.html.
If I change function handleDataChanged(event) like this:

public function handleDataChanged(event:Event):void {
// Cast listData to DataGridListData.
var myListData:DataGridListData=
DataGridListData
(listData);
/////////////////////////////////////////////
// I want to disable this cell
if (myListData.rowIndex == 0 &&
myListData.columnIndex == 1) {
this.enabled = false;
}
//////////////////////////////////////////////
// Access information about the data passed
// to the cell renderer.
text="row index: " + String(myListData.rowIndex)
+ " column index: " + String(myListData.columnIndex);
}

It works well at first, however when I click sort on the head of
every column, weird thing happened. Both those two cells were
disabled, I tried several times and add more than two cells, there
are always more than one cells were disabled. In debug mode, I can
make sure that this change is not triggered by code "this.enabled =
false;", because it's only executed once.

I don't know why and can you help me to find out the reason?
Thanks very much.

Jackoo

Following is the completed source code:

<?xml version="1.0"?>
<!-- itemRenderers\dataGrid\myComponents\RendererDGListData.mxml -->
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml";
preinitialize="initTA();">

<mx:Script>
<![CDATA[

import mx.controls.dataGridClasses.DataGridListData;
import flash.events.Event;

public function initTA():void {
addEventListener("dataChange", handleDataChanged);
}

public function handleDataChanged(event:Event):void {
// Cast listData to
DataGridListData.
var myListData:DataGridListData=
DataGridListData(listData);

/////////////////////////////////////////////
// I want to disable this cell
if (myListData.rowIndex == 0 &&
myListData.columnIndex == 1) {
this.enabled = false;
}

//////////////////////////////////////////////
// Access information about the
data passed
// to the cell renderer.
text="row index: " + String
(myListData.rowIndex) + " column index: " + String
(myListData.columnIndex);
}
]]>
</mx:Script>
</mx:TextArea>


<?xml version="1.0"?>
<!-- itemRenderers\dataGrid\MainDGListDataRenderer.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

[Bindable]
public var initDG:ArrayCollection = new ArrayCollection([
{ Company: 'Acme', Contact: 'Bob Jones',
Phone: '413-555-1212', Date: '5/5/05'},
{ Company: 'Allied', Contact: 'Jane Smith',
Phone: '617-555-3434', Date: '5/6/05'}
]);
]]>
</mx:Script>

<mx:Panel paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10" >

<mx:DataGrid id="myGrid" dataProvider="{initDG}"
variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn dataField="Company"
itemRenderer="myComponents.RendererDGListData"/>
<mx:DataGridColumn dataField="Contact"
itemRenderer="myComponents.RendererDGListData"/>
<mx:DataGridColumn dataField="Phone"
itemRenderer="myComponents.RendererDGListData"/>
<mx:DataGridColumn dataField="Date"
itemRenderer="myComponents.RendererDGListData"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:Application>

Reply via email to