20 Replies Latest reply on Oct 5, 2009 7:19 AM by wendy888

    _Natasha, can you help me on this?

    wendy888 Level 1

      I have new problem on the datagrid column. I need to create a check box on the second column and there are compile error saying that Access of undefined property cboActivities. See attached files for codes. Column one works fine.

       

      thank you in advance.

       

      Wendy

        • 1. Re: _Natasha, can you help me on this?
          _Natasha_ Level 4

          Hi,

           

          <mx:DataGridColumn headerText="  Gift" >

           

           

          <mx:itemRenderer>

                              <mx:Component>

                              <checkBoxItemRenderer:CBItemRenderer dataField="{'col2'+ outerDocument.cboActivities.selectedItem.@event_id}" />                       

                              </mx:Component>

                          </mx:itemRenderer>

          </mx:DataGridColumn>

          1 person found this helpful
          • 2. Re: _Natasha, can you help me on this?
            wendy888 Level 1

            Natasha,

                  thank you very much for your help.

                 If I use

            dataField="{'col2'+ *outerDocument*.cboActivities.selectedItem.@event_id}", it will give an syntax error saying expecting rightparen before outerdocument.

            if I use

             

            dataField="{'col2'+ outerDocument.cboActivities.selectedItem.@event_id}", there is not error on compiling, but it hangs up there when I select a ID from ComboBox.

            Any idea?

            • 3. Re: _Natasha, can you help me on this?
              _Natasha_ Level 4

              This should work.

               

              What error did you get?

              • 4. Re: _Natasha, can you help me on this?
                wendy888 Level 1

                Hi Natasha,

                    if I use

                 

                <checkBoxItemRenderer:CBItemRenderer dataField="{'col2'+ *outerDocument*.cboActivities.selectedItem.@event_id}" /> , there is error (see attched file)

                If I take off * from outerDocument, the program either hanging when I select the ID from ComboBox (cooperate with the datagrid) or list only one row on datagrid(should be two rows). The checkbox was in the first column (it should be in second column).

                 

                Please help!

                 

                Wendy

                • 5. Re: _Natasha, can you help me on this?
                  _Natasha_ Level 4

                  You don't need *.

                   

                  Correct is this one:

                  <checkBoxItemRenderer:CBItemRenderer dataField="{'col2'+ outerDocument.cboActivities.selectedItem.@event_id}" />

                  • 6. Re: _Natasha, can you help me on this?
                    wendy888 Level 1

                    Hi,

                       This one gave me syntax error: expectin rightparen before col2

                    dataField="{*'col2'*+ outerDocument.cboActivities.selectedItem.@event_id}

                    What does mean to put *?

                    sorry for too many questions and I just started a new project wiht Flex. It is totally new to me.

                     

                    • 7. Re: _Natasha, can you help me on this?
                      _Natasha_ Level 4

                      Where do you see using *? You don't need * at all!!!

                      dataField="{'col2' + outerDocument.cboActivities.selectedItem.@event_id}"

                       

                      What error did you get at runtime?

                      • 8. Re: _Natasha, can you help me on this?
                        wendy888 Level 1

                        Hi,

                            My received email add * into col2. Sorry.

                            Yes, without *, it is not error at compile time. At the run time, the program was hanging a while and then display only one row. Also, the checkbox is supposed to in column2, but it was located in column1. See attached.

                        Thank you so much for your help!

                         

                        Wendy

                        • 9. Re: _Natasha, can you help me on this?
                          _Natasha_ Level 4

                          Can you post a error?

                          • 10. Re: _Natasha, can you help me on this?
                            wendy888 Level 1

                            Hi Natasha,

                                Just got my debug tool fixed and now I can see runtime error.

                               The error as below:

                                Error #1010: A term is undefined and has no properties.

                                I know the under certain IDs, there are no values for datagrid to display. How to handle this situation?

                            • 11. Re: _Natasha, can you help me on this?
                              _Natasha_ Level 4

                              Can you post a code where you get a error?

                              • 12. Re: _Natasha, can you help me on this?
                                wendy888 Level 1

                                when there are values in "association" then the error occurs when I selected a ID in ComboBox. If There are not value to show in the datagrid, then no errors.

                                 

                                <mx:ComboBox

                                 

                                id="cboActivities" prompt="Please select an activity ID" dataProvider="{activityXML}" labelField="@event_id" x="121" y="87">

                                 

                                 

                                </mx:ComboBox>

                                 

                                *******************************

                                <mx:DataGrid x="10" y="318" id="dgAssociation" dataProvider="{cboActivities.selectedItem.association}" columnWidth="100" height="100" editable="false" width="272">

                                      <mx:columns>

                                         <mx:DataGridColumn headerText="       Association      "

                                                        dataField="{'col1'+ cboActivities.selectedItem.@event_id}" id="dgcol1" />

                                 

                                        <mx:DataGridColumn editable="false"  headerText="  Attribute Gift  " id="dgcol2" >

                                        <mx:itemRenderer>

                                              <mx:Component> 

                                                     

                                           <checkBoxItemRenderer:CBItemRenderer dataField="{'col2' + outerDocument.cboActivities.selectedItem.@event_id}" />                       

                                        

                                          </mx:Component>

                                        </mx:itemRenderer>   

                                      </mx:DataGridColumn>          

                                      </mx:columns>

                                   </mx:DataGrid>

                                **********************

                                below is the ItemRendere codes:

                                package

                                 

                                 

                                import flash.events.Event;

                                 

                                import flash.events.MouseEvent;

                                 

                                 

                                import mx.controls.CheckBox;

                                 

                                import mx.controls.DataGrid;

                                 

                                import mx.controls.dataGridClasses.DataGridColumn;

                                 

                                import mx.controls.listClasses.ListBase;

                                 

                                import mx.events.FlexEvent;

                                 

                                 

                                public class CBItemRenderer extends CheckBox

                                {

                                 

                                private var _dataField:String;

                                 

                                private var _enabledField:String;

                                 

                                 

                                public function CBItemRenderer()

                                {

                                 

                                super();

                                setStyle(

                                "textAlign","center");

                                }

                                 

                                 

                                override public function set data(value:Object):void {

                                 

                                super.data = value;

                                 

                                if (value != null) {

                                 

                                if( _dataField == null ){

                                 

                                throw new Error("No data field");

                                }

                                 

                                if(value.hasOwnProperty(_enabledField)){

                                 

                                this.enabled = data[_enabledField];

                                }

                                }

                                }

                                 

                                 

                                override public function validateProperties():void

                                {

                                 

                                super.validateProperties();

                                selected = data[_dataField];

                                }

                                 

                                 

                                 

                                override protected function clickHandler(event:MouseEvent):void

                                {

                                 

                                super.clickHandler(event);

                                clickOpp();

                                 

                                }

                                 

                                public function set dataField(dataField:String):void{

                                _dataField = dataField;

                                }

                                 

                                public function set enabledField(enabledField:String):void{

                                _enabledField = enabledField;

                                }

                                 

                                private function clickOpp():void{

                                 

                                if(data.hasOwnProperty( _dataField ) && _dataField!=""){

                                data[_dataField] = selected;

                                }

                                 

                                else if( !data.hasOwnProperty( _dataField ) && _dataField!="" )

                                {

                                 

                                throw new Error("Data Field is not available in Data Object ");

                                }

                                }

                                }

                                }

                                 

                                 

                                edu.yu.checkBoxItemrenderer

                                {

                                 

                                • 13. Re: _Natasha, can you help me on this?
                                  _Natasha_ Level 4

                                  Try

                                   

                                  cboActivities.selectedItem.child('association')

                                  • 14. Re: _Natasha, can you help me on this?
                                    wendy888 Level 1

                                    Natasha,

                                    Thank you very much for your reply. I still got the same error if the association has values (select ID from ComboBox):

                                    ****************************************************************************************** ************************

                                    TypeError: Error #1010: A term is undefined and has no properties.
                                    at XML/http://adobe.com/AS3/2006/builtin::hasOwnProperty()
                                    at edu.yu.checkBoxItemrenderer::CBItemRenderer/set data()[C:\Documents and Settings\WU\My Documents\Flex Builder 3\testdatagrid\src\edu\yu\checkBoxItemrenderer\CBItemRenderer.as:29]
                                    at mx.controls.dataGridClasses::DataGridBase/setupColumnItemRenderer()[C:\autobuild\3.2.0\fr ameworks\projects\framework\src\mx\controls\dataGridClasses\DataGridBase.as:1072]
                                    at mx.controls.dataGridClasses::DataGridBase/makeRow()[C:\autobuild\3.2.0\frameworks\project s\framework\src\mx\controls\dataGridClasses\DataGridBase.as:822]
                                    at mx.controls.dataGridClasses::DataGridBase/makeRows()[C:\autobuild\3.2.0\frameworks\projec ts\framework\src\mx\controls\dataGridClasses\DataGridBase.as:687]
                                    at mx.controls.dataGridClasses::DataGridBase/makeRowsAndColumns()[C:\autobuild\3.2.0\framewo rks\projects\framework\src\mx\controls\dataGridClasses\DataGridBase.as:593]
                                    at mx.controls::DataGrid/makeRowsAndColumns()[C:\autobuild\3.2.0\frameworks\projects\framewo rk\src\mx\controls\DataGrid.as:1538]
                                    at mx.controls.listClasses::ListBase/makeRowsAndColumnsWithExtraRows()[C:\autobuild\3.2.0\fr ameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:1360]
                                    at mx.controls.listClasses::ListBase/updateDisplayList()[C:\autobuild\3.2.0\frameworks\proje cts\framework\src\mx\controls\listClasses\ListBase.as:3658]
                                    at mx.controls.dataGridClasses::DataGridBase/updateDisplayList()[C:\autobuild\3.2.0\framewor ks\projects\framework\src\mx\controls\dataGridClasses\DataGridBase.as:581]
                                    at mx.controls::DataGrid/updateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:1437]
                                    at mx.controls.listClasses::ListBase/validateDisplayList()[C:\autobuild\3.2.0\frameworks\pro jects\framework\src\mx\controls\listClasses\ListBase.as:3280]
                                    at mx.managers::LayoutManager/validateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\f ramework\src\mx\managers\LayoutManager.as:622]
                                    at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects \framework\src\mx\managers\LayoutManager.as:695]
                                    at Function/http://adobe.com/AS3/2006/builtin::apply()
                                    at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framew ork\src\mx\core\UIComponent.as:8628]
                                    at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framewo rk\src\mx\core\UIComponent.as:8568]
                                    at flash.events::EventDispatcher/dispatchEventFunction()
                                    at flash.events::EventDispatcher/dispatchEvent()
                                    at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9298]
                                    at mx.controls.listClasses::ListBase/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects \framework\src\mx\controls\listClasses\ListBase.as:8989]
                                    at mx.controls::List/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\m x\controls\List.as:2279]

                                    • 15. Re: _Natasha, can you help me on this?
                                      _Natasha_ Level 4

                                      According to this message problem is

                                      What is the value of _enabledField here? I can't see where it's set.

                                       

                                      override public function set data(value:Object):void {

                                       

                                       

                                      super.data = value;

                                       

                                       

                                      if (value != null) {

                                       

                                       

                                      if( _dataField == null ){

                                       

                                       

                                      throw new Error("No data field");

                                      }

                                      //trace(_enabledField);

                                       

                                      if(value.hasOwnProperty(_enabledField)){

                                       

                                       

                                      this.enabled = data[_enabledField];

                                      }

                                      }

                                      }

                                       

                                       

                                      1 person found this helpful
                                      • 16. Re: _Natasha, can you help me on this?
                                        wendy888 Level 1

                                        Yes, you are right. Thank you so much.

                                        After I add

                                        enabledField ="" and then there is no error. There is new problem --I could not get the false/ true value in selected field. Even I force selected="false" inline, but it still selected all for both rows. Any idea? Sorry for too many questions.

                                         

                                        <association>
                                        <col1YUD09>ALL</col1YUD09>
                                        <col2YUD09>false</col2YUD09>
                                        </association>
                                        <association>
                                        <col1YUD09>HON</col1YUD09>
                                        <col2YUD09>true</col2YUD09>
                                        </association>

                                        • 17. Re: _Natasha, can you help me on this?
                                          _Natasha_ Level 4

                                          It's as exepected. Any string will be converted to true.

                                           

                                          this.enabled = data[_enabledField]; // will be always true

                                          this.enabled = (data[_enabledField].toString() == "true"); // what you need!

                                          • 18. Re: _Natasha, can you help me on this?
                                            wendy888 Level 1

                                            Natasha,

                                                  Thank you very much. It works.

                                                  Would you recommend a book that I can read for learning Flex programming. I have not done any OOP and web program before.

                                                 Another issue is that if the checkbox is false, the box is grey, but it still has the check mark. How to get ride of it?

                                            Wendy

                                            • 19. Re: _Natasha, can you help me on this?
                                              _Natasha_ Level 4

                                              As a docs - the best variant is to read original docs

                                              http://www.adobe.com/support/documentation/en/flex/

                                               

                                              There books about Flex and AS there.

                                              But sometimes your questions is from basic programming courses. It's something like

                                              Data Structures and Algorithms First Edition
                                              Alfred V. Aho, Jeffrey D. Ullman, John E. Hopcroft

                                              or there is a similar book by N.Virt.

                                               

                                               

                                              I can't see any code with checkboxes.

                                              • 20. Re: _Natasha, can you help me on this?
                                                wendy888 Level 1

                                                Thank you very much for your information. See below my checkBoxItemrenderer (it was adopted)

                                                package edu.yu.checkBoxItemrenderer

                                                 

                                                {
                                                import flash.events.Event;
                                                import flash.events.MouseEvent;

                                                import mx.controls.CheckBox;
                                                import mx.controls.DataGrid;
                                                import mx.controls.dataGridClasses.DataGridColumn;
                                                import mx.controls.listClasses.ListBase;
                                                import mx.events.FlexEvent;

                                                public class CBItemRenderer extends CheckBox
                                                {
                                                  private var _dataField:String;
                                                  private var _enabledField:String;
                                                       
                                                  public function CBItemRenderer()
                                                  {
                                                   super();
                                                            setStyle("textAlign","center");
                                                        }
                                                  override public function set data(value:Object):void {
                                                           super.data = value;                
                                                           if (value != null) {   
                                                                if( _dataField == null ){
                                                                    throw new Error("No data field");
                                                                }                      
                                                                if(value.hasOwnProperty(_enabledField)){
                                                                    this.enabled = data[_enabledField];
                                                                }
                                                            }
                                                        }

                                                        override public function validateProperties():void
                                                        {
                                                            super.validateProperties();
                                                            selected = data[_dataField];           
                                                        }


                                                        override protected function clickHandler(event:MouseEvent):void
                                                        {
                                                           super.clickHandler(event);
                                                           clickOpp();

                                                        }
                                                        public function set dataField(dataField:String):void{
                                                              _dataField = dataField;
                                                        }
                                                        public function set enabledField(enabledField:String):void{
                                                              _enabledField = enabledField;
                                                        }
                                                        private function clickOpp():void{
                                                         if(data.hasOwnProperty( _dataField ) && _dataField!=""){
                                                                 data[_dataField] = selected;
                                                            }
                                                            else if( !data.hasOwnProperty( _dataField ) && _dataField!="" )
                                                            {
                                                                throw new Error("Data Field is not available in Data Object ");
                                                            }
                                                        }
                                                }
                                                }