header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Ramakrishna
Points:0
Posts:0

5/26/2010 12:18:19 AM

Title: Check Box Item Renderer


Hi,

I have a datagrid, In the datagrid I have check box itemrender, When ever i select particular row , multiple rows that are all will be added in the database, I want logic for this. can anybody having the code, Please help me , its urgent for me.

Thanks in advance
Ramakrishna




1
NileshPawar
Points: 180
Posts:0
5/26/2010 5:26:39 AM



Rama,
Did you mean you can you want all checkboxes should be selected when you check the header checkbox of DataGrid?

2
NileshPawar
Points: 180
Posts:0
5/26/2010 5:31:31 AM



Try out these renderers for DataGrid -

<!-- CheckBoxHeaderRenderer.mxml -->


<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
    implements="mx.controls.listClasses.IDropInListItemRenderer"
    creationComplete="onComplete()">
    
    <mx:Script>
        <![CDATA[
            import mx.events.CollectionEvent;
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.collections.ArrayCollection;
            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.controls.listClasses.BaseListData;
            
            private var _listData:BaseListData;
            private var _dataGrid:DataGrid;
            private var _dataField:String;
            [Bindable] private var _CBselected:Boolean;
            [Bindable] private var _headerLabel:String;
            
            private function onComplete():void {
                cb.setStyle("fontWeight", this.getStyle("fontWeight"));
            }
            
            [Bindable("dataChange")]
            public function get listData():BaseListData
            {
                return _listData;
            }
        
            public function set listData(value:BaseListData):void
            {
                _listData = value;
                //_dataGrid = value.owner as DataGrid;
                _dataField = (value as DataGridListData).dataField;
                _headerLabel = value.label;
            }
            
            override public function set data(value:Object):void {
                super.data = value;
                
                var column:DataGridColumn = value as DataGridColumn;
                column.sortable = false;
                
                checkForSelectedItems();
            }
            
            private function checkForSelectedItems():void {
                var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
                var n:Number = 0;
                for(var i:int=0 ; i < dp.length ; i++){
                    if(dp[i][_dataField])
                        n++
                }
                if(n == dp.length){
                    _CBselected = true;
                }
            }
            
            private function onCBchange(event:Event):void {
                var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
                
                for(var i:int=0 ; i < dp.length ; i++){
                    dp[i][_dataField] = cb.selected;
                }
                _dataGrid.invalidateList();
            }
            
        ]]>
    </mx:Script>
    <mx:CheckBox id="cb" horizontalCenter="0" useHandCursor="true" buttonMode="true"
        change="onCBchange(event)" selected="{_CBselected}" />
</mx:Canvas>



<!-- CheckBoxItemRenderer.mxml -->



<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas top="0" xmlns:mx="http://www.adobe.com/2006/mxml" 
    implements="mx.controls.listClasses.IDropInListItemRenderer">
    <mx:Script>
        <![CDATA[
            import mx.events.CollectionEvent;
            import mx.collections.ArrayCollection;
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.DataGrid;
            import mx.controls.listClasses.BaseListData;
            
            private var _listData:BaseListData;
            private var _dataGrid:DataGrid;
            private var _dataField:String;
            
            
            [Bindable("dataChange")]
            public function get listData():BaseListData
            {
                return _listData;
            }
            public function set listData(value:BaseListData):void {
                _listData = value;
                _dataGrid = value.owner as DataGrid;
                _dataField = (value as DataGridListData).dataField;
            }
            
            override public function set data(value:Object):void {
                super.data = value;
                cb.selected = value[_dataField];
            }
            
            private function onChange():void {
                data[_dataField] = cb.selected;
                var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
                dp.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
            }
        ]]>
    </mx:Script>
    <mx:CheckBox paddingTop="2" paddingBottom="10" id="cb" horizontalCenter="0" change="onChange()" />
</mx:Canvas>

Hope this helps you to solve your problem.

3
NileshPawar
Points: 180
Posts:0
5/26/2010 5:32:44 AM



Remove commented line --> "_dataGrid = value.owner as DataGrid;" from <!-- CheckBoxHeaderRenderer.mxml -->

4
Rosewell
Points: 0
Posts:0
5/26/2010 6:11:56 AM



you can get a list of all your selected items in datagrid as array by using property selectedItems, myDataGrid.selectedItems.

Know to send all these items to database you need to call an http service and send the array by converting it to string. The http service can receive the string and save in the databsse


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 6+0 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions