You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Philip Medlam <ph...@gmail.com> on 2019/09/11 11:06:13 UTC

Access to CheckBox in a DataGrid

Hi everyone,

Not used Flex/AS3 for some time and am after some information.

If anyone can help:
I have a Spark dataGrid with: 
Column1 = some text
Column2 = Checkbox

I wish to check to checkbox when any part of the row is clicked.
Now I know which row has been clicked, but how the hell do I set the
checkBox to be checked/unchecked.

FYI:
I am using FlexSDK 4.16 and AIR SDK 29.0.0.122

Many thanks to anyone who can reply

CODE:
==============================

[Bindable]
public var countryData:ArrayCollection = new ArrayCollection
([
   {value:"France", code:0},
   {value:"Japan", code:0},
   {value:"India", code:1},
   {value:"Russia", code:0},
   {value:"United States", code:0}
]);


private function selectionChangingHandler(evt:MouseEvent):void
{
   trace("Row Selected = " + dg.selectedIndex);
}

==============================


<s:DataGrid id="dg" width="85%" editable="false"
dataProvider="{countryData}"
           selectionColor="yellow" sortableColumns="false" enabled="true"
           click="selectionChangingHandler(event)">
   <s:columns>
       <s:ArrayCollection>
           <s:GridColumn  dataField="value" headerText="Country"
width="90%" editable="false"/>

           <s:GridColumn headerText="Delete" dataField="active"
rendererIsEditable="true" width="15%" editable="true">
               <s:itemRenderer>
                   <fx:Component>
                       <s:GridItemRenderer>
                           <s:CheckBox id="cb1" selected="false" 
horizontalCenter="0" verticalCenter="3"/>
                       </s:GridItemRenderer>
                   </fx:Component>
               </s:itemRenderer>
           </s:GridColumn>

       </s:ArrayCollection>
   </s:columns>
</s:DataGrid>

==============================

Phil.


Re: Access to CheckBox in a DataGrid

Posted by Alex Harui <ah...@adobe.com.INVALID>.
Another way is to have a custom renderer that checks its index and the DataGrid's selectedIndex and decides whether to display the check or not.  The index and reference to the DataGrid are in the "listData" property of a custom IDropInListItemRenderer (which is of type DataGridListData).

I'm not sure one way is better than the other.  Also, some folks don't even use a real CheckBox, they just display the graphic.

-Alex

On 9/11/19, 4:40 AM, "Olaf Krueger" <ma...@olafkrueger.net> wrote:

    Hi,
    
    one way is to introduce a boolean flag, e.g. 'checked' within your data
    model which is 'countryData'.
    After clicking a row, you have to set this flag to 'true' for the related
    row.
    
    Within the item renderer, you have to evaluate the 'checked' property in
    order to update the 'selected' property of the checkbox.
    
    Hope this helps!
    
    Olaf
    
    
    
    
    
    --
    Sent from: https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-flex-users.2333346.n4.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7Cbab8d033570a4a1f231408d736acd277%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C1%7C637037988247042278&amp;sdata=RGG2W7C5DQMeDrHhOScXMDBhDIRO87w6S2P4ZMrWJfc%3D&amp;reserved=0
    


Re: Access to CheckBox in a DataGrid

Posted by Olaf Krueger <ma...@olafkrueger.net>.
Hi,

one way is to introduce a boolean flag, e.g. 'checked' within your data
model which is 'countryData'.
After clicking a row, you have to set this flag to 'true' for the related
row.

Within the item renderer, you have to evaluate the 'checked' property in
order to update the 'selected' property of the checkbox.

Hope this helps!

Olaf





--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/