View Full Version : Checkbox in a DataGrid (Problems)

10-12-2010, 09:12 PM
Hi everyone!

This is my first topic, so I'm sorry if I didn't post it in the right place, but I hope you could help me still.

I have a checkbox in a datagrid. The problem comes when I select a checkbox, and then I move to the bottom of my datagrid, when I go back to the top of de datagrid, the checkbox is no more selected. Maybe the pics will help me to explain it:


Here is the code of the datagrid:

<mx:DataGrid width="937" height="242" horizontalCenter="0" variableRowHeight="true" textAlign="center" verticalAlign="middle" id="dg_progfed" editable="true" itemFocusOut="insertMontoHandler_click(event)" dataProvider="{acDGProgFed}" verticalCenter="0">
<mx:DataGridColumn headerText="Programa" dataField="programa" sortable="false" wordWrap="true" textAlign="left" editable="false" id="columnaProg"/>
<mx:DataGridColumn headerText="Monto $" dataField="monto" sortable="false" wordWrap="true" width="150" editable="true" id="columnaMonto">
<mx:TextInput restrict="0-9"/>
<mx:DataGridColumn headerText="żOpera?" dataField="opera" sortable="false" wordWrap="true" width="90" textAlign="center" editable="false" id="columnaOpera">
<mx:CheckBox label="S/N" click="outerDocument.actualizaSNOperaHandler_click(data.c veprog,this.selected)" selected="{data.sn3 == 'S' ? true : false}"/>


Thank you very much in advance.

Arturo from Mexico

10-16-2010, 07:48 PM
This problem occurs because Flex reuses itemRenderers. In other words, you don't get one itemRenderer per row on your datagrid. And, to complicate the problem, you only have itemRenderers for the visible rows. So, when you scroll down to where your upper row's checkbox is no longer visible, and then scroll back up, all sorts of weird things can happen as itemRenderers are re-used.

I would give you some links to read up on this, but I don't have 50 posts yet, and am therefore not able to post them. So, just Google "flex datagrid itemrenderer reuse" and you will get some good information on overriding the set data method.

Ron Grimes