[flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Fernando Wermus
Hi all,
   I just want to check and uncheck a checkbox in a datagrid. What I do is
to add or remove from the selected's collection. But I got an error index
when removing. Futhermore, the checked item change! when I move the datagrid
scroll bar. This is my code,













-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus

-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus


Re: [flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Oleg Sivokon
Hi, the list based controls may reuse the item renderers, however they might
not be aware of the changes that had happened to them. Normally you would
store the state with the data which the renderer has to display. So that
once the data is reset, the render appearance would reset with it. If, for
whatever reason you cannot store the state of the renderer with the data,
you would have to store the references to either manage the how the item
renderers are created (by using the itemRendereFunction for example), or
update the display of the control whenever the new (or an old new) item
renderer is added - IMO complicated.


Re: [flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Fernando Wermus
Oleg,
I cant associate the state with the data, and I cant find any info
about itemRendereFunction. Do you have any link about it? According to my
code, I would think this just should happen.

I re write down my code:








On Tue, Apr 27, 2010 at 3:10 PM, Oleg Sivokon  wrote:

>
>
> Hi, the list based controls may reuse the item renderers, however they
> might not be aware of the changes that had happened to them. Normally you
> would store the state with the data which the renderer has to display. So
> that once the data is reset, the render appearance would reset with it. If,
> for whatever reason you cannot store the state of the renderer with the
> data, you would have to store the references to either manage the how the
> item renderers are created (by using the itemRendereFunction for example),
> or update the display of the control whenever the new (or an old new) item
> renderer is added - IMO complicated.
>
>  
>



-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus


Re: [flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Oleg Sivokon
http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/spark/components/DataGroup.html#itemRendererFunction
( this is Flex 4, it didn't exist in Flex 3 )

But, no, it shouldn't work like that out of the box because renderers are
reused, when the list based control lays out a renderer it may use an old
one (since flex controls are in general very heavy, and it would be a huge
waste of resources to create them every time anew, or let you have a lot of
them in memory at a time). So, list based controls create the number of
visible renderers + 2-8 additional renderers for cases like scrolling.

If there aren't to many renderers, you could tell a parentDocument from
inside the item renderer, if the CB is checked, and then once the list
scrolls, the renderer would have it's data property reset, then, it could
check against parent document, and if it's index is registered as checked,
it would set the CB to checked, else, it would uncheck it.

Think of something like this:

public override function set data(value:Object):void
{
if ( this.parentDocument.amIChecked( this ) this.checkBox.checked = true;
else this.checkBox.checked = true;
super.data = value;
}

private function cb_clickHandler(event:MouseEvent):void
{
this.parentDocument.checkMe( this, (event.currentTarget as
CheckBox).checked);
}

/* parent document */

public function amIChecked(renderer:ItemRenderer):Boolean
{
return this._allCheckedArray[dg.itemIndex(renderer)];
}

public function checkMe(renderer:ItemRenderer, checked:Boolean):void
{
return this._allCheckedArray[dg.itemIndex(renderer)] = checked;
}


Re: [flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Oleg Sivokon
Sorry, I've got that one wrong :)

public override function set data(value:Object):void
{
this.checkBox.checked =  this.parentDocument.amIChecked(this);
super.data = value;
}


Re: [flexcoders] checkbox change while I move the datagrid scroll bar

2010-04-27 Thread Fernando Wermus
Oleg,
Thanks! I don't have Flex 4 so I cant try by this way. I would add the
selected attribute to the VO.


On Tue, Apr 27, 2010 at 5:53 PM, Oleg Sivokon  wrote:

>
>
> Sorry, I've got that one wrong :)
>
> public override function set data(value:Object):void
> {
> this.checkBox.checked =  this.parentDocument.amIChecked(this);
> super.data = value;
> }
>
>  
>



-- 
Fernando Wermus.

www.linkedin.com/in/fernandowermus