7 Replies Latest reply on Mar 10, 2010 1:46 AM by bodrul haque

    Combobox with a DataGrid dropdown factory runtime error

    bodrul haque

      I am getting the runtime error - ArgumentError: Error #1063: Argument count mismatch on mx.controls::ComboBox/itemToLabel(). Expected

       

      Any ideas?

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">

       

           <mx:ComboBox id="cb" labelField="fname">

                <mx:dataProvider>

                    <mx:Object fname="one" lname="1"/>

                    <mx:Object fname="two" lname="2"/>

                    <mx:Object fname="three" lname="3"/>

                    <mx:Object fname="four" lname="4"/>

                    <mx:Object fname="five" lname="5"/>

                </mx:dataProvider>

                <mx:dropdownFactory>

                      <mx:Component>

                            <mx:DataGrid showHeaders="false">

                                  <mx:columns>

                                       <mx:Array>

                                             <mx:DataGridColumn dataField="fname"/>

                                             <mx:DataGridColumn dataField="lname"/>

                                       </mx:Array>

                                   </mx:columns>

                            </mx:DataGrid>

                       </mx:Component>

                 </mx:dropdownFactory>

              </mx:ComboBox>

       

      </mx:Application>

        • 1. Re: Combobox with a DataGrid dropdown factory runtime error
          Flex harUI Adobe Employee

          Which version of the SDK?  I thought this was recently fixed.

          • 2. Re: Combobox with a DataGrid dropdown factory runtime error
            bodrul haque Level 1

            Yes it has. Just tried it on the latest nightly build(4.1.0.14607).

            Thanks Alex.

            • 3. Re: Combobox with a DataGrid dropdown factory runtime error
              bodrul haque Level 1

              No. I spoke too soon. There is one other problem.

               

              The RTE has been fixed but columns are showing "fname" values. Second column should be showing "lname" values.

               

              <mx:DataGridColumn dataField="fname"/>

              <mx:DataGridColumn dataField="lname"/>

               

               

              I've tested on the nightly build (4.1.0.14607) and stable stable build (4.0.0.13875).

              • 4. Re: Combobox with a DataGrid dropdown factory runtime error
                Flex harUI Adobe Employee

                What does your code look like now?

                • 5. Re: Combobox with a DataGrid dropdown factory runtime error
                  bodrul haque Level 1

                  Its the same code as I posted in my original post. (Its a simple example based on my flex 3 code). 

                  • 6. Re: Combobox with a DataGrid dropdown factory runtime error
                    Peter deHaan Level 4

                    Looks like you can set a labelFunction to get the correct behavior:

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                       
                        <mx:ComboBox id="cb" labelField="fname" dropdownWidth="200">
                            <mx:dataProvider>
                                <mx:Object fname="one" lname="1 ONE"/>
                                <mx:Object fname="two" lname="2 TWO"/>
                                <mx:Object fname="three" lname="3 THREE"/>
                                <mx:Object fname="four" lname="4 FOUR"/>
                                <mx:Object fname="five" lname="5 FIVE"/>
                            </mx:dataProvider>
                            <mx:dropdownFactory>
                                <mx:Component>
                                    <mx:DataGrid showHeaders="false">
                                        <mx:Script>
                                            <![CDATA[
                                                protected function grid_labelFunc(item:Object, col:DataGridColumn):String {
                                                    return item[col.dataField];
                                                }
                                            ]]>
                                        </mx:Script>
                                        <mx:columns>
                                            <mx:Array>
                                                <mx:DataGridColumn dataField="fname" labelFunction="grid_labelFunc" />
                                                <mx:DataGridColumn dataField="lname" labelFunction="grid_labelFunc"/>
                                            </mx:Array>
                                        </mx:columns>
                                    </mx:DataGrid>
                                </mx:Component>
                            </mx:dropdownFactory>
                        </mx:ComboBox>
                       
                    </mx:Application>

                     

                     

                    You may want to file a bug at http://bugs.adobe.com/flex/ and attach your simple test case.

                     

                    Peter

                    1 person found this helpful
                    • 7. Re: Combobox with a DataGrid dropdown factory runtime error
                      bodrul haque Level 1

                      Yes, that worked thanks. I will file a bug (I would prefer to see it working as it did in Flex 3).

                       

                       

                      --

                       

                       

                      Just to let you know, I came across an issue when making this into a mxml component. Your code works fine but when I change the example to use the "outerDocument" function notation it doesnt work (gives an RTE) eg

                       

                      <mx:DataGridColumn dataField="fname" labelFunction="grid_labelFunc"/> // works

                      <mx:DataGridColumn dataField="fname" labelFunction="outerDocument.grid_labelFunc"/> // doesnt work

                       

                      There is a workaround for this (full details below), so i'm not too worried.......I'd rather see the original problem get fixed.

                       

                       

                       

                      Full example

                       

                       

                      eg 1 - MyComboBox.mxmxl - doesnt work

                      <?xml version="1.0" encoding="utf-8"?>

                      <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">

                       

                      <mx:Script>

                         <![CDATA[

                          public function grid_labelFunc(item:Object, col:DataGridColumn):String

                          {

                              return item[col.dataField];

                          }

                         ]]>

                      </mx:Script>

                       

                      <mx:dropdownFactory>

                           <mx:Component>

                                 <mx:DataGrid showHeaders="false">

                                        <!--mx:Script>

                                         <![CDATA[

                                                 // Move this function to outer script block

                                                 protected function grid_labelFunc(item:Object, col:DataGridColumn):String

                                                 {

                                                    return item[col.dataField];

                                                 }

                                           ]]>

                                     </mx:Script-->

                                     <mx:columns>

                                         <mx:Array>

                                                <mx:DataGridColumn dataField="fname" labelFunction="outerDocument.grid_labelFunc"/>

                                                <mx:DataGridColumn dataField="lname" labelFunction="outerDocument.grid_labelFunc"/>

                                         </mx:Array>

                                    </mx:columns>

                                 </mx:DataGrid>

                            </mx:Component>

                      </mx:dropdownFactory>

                      </mx:ComboBox>

                       

                      (testAPP looks like this

                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">

                      <MyComboBox/>

                      </mx:Application>)

                       

                      this gives a runtime error

                      TypeError: Error #1009: Cannot access a property or method of a null object reference.

                      at SynComboInnerClass0/_SynComboInnerClass0_DataGridColumn1_c()[C:\Documents and Settings\bodrul haque.SYNLOG\My Documents\Adobe Flash Builder Plug-in Beta 2\myTest\src\SynCombo.mxml:63]

                      at SynComboInnerClass0()[C:\Documents and Settings\bodrul haque.SYNLOG\My Documents\Adobe Flash Builder Plug-in Beta 2\myTest\src\SynCombo.mxml:60]

                      at mx.core::ClassFactory/newInstance()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\cor e\ClassFactory.as:172]

                      at mx.controls::ComboBox/getDropdown()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\con trols\ComboBox.as:1678]

                      at mx.controls::ComboBox/displayDropdown()[E:\dev\4.0.0\frameworks\projects\framework\src\mx \controls\ComboBox.as:1768]

                      at mx.controls::ComboBox/downArrowButton_buttonDownHandler()[E:\dev\4.0.0\frameworks\project s\framework\src\mx\controls\ComboBox.as:2004]

                      at flash.events::EventDispatcher/dispatchEventFunction()

                      at flash.events::EventDispatcher/dispatchEvent()

                      at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12269]

                      at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::buttonPressed()[E:\dev\4.0.0\frameworks\projec ts\framework\src\mx\controls\Button.as:2445]

                      at mx.controls::Button/mouseDownHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ controls\Button.as:2706]

                       

                       

                       

                      eg2 - this works - set label function during dg initialize event

                       

                      <?xml version="1.0" encoding="utf-8"?>

                      <mx:ComboBox etc>

                       

                      <mx:Script>

                        <![CDATA[

                          public function dgStartUP(e:FlexEvent):void

                          {

                               // Set label function

                               DataGrid(e.currentTarget).columns[0].labelFunction = grid_labelFunc;

                               DataGrid(e.currentTarget).columns[1].labelFunction = grid_labelFunc;

                          } 

                       

                          public function grid_labelFunc(item:Object, col:DataGridColumn):String

                          {

                                return item[col.dataField];

                          }

                        ]]>

                      </mx:Script>

                       

                      <mx:dropdownFactory>

                           <mx:Component>

                               <mx:DataGrid showHeaders="false" initialize="outerDocument.dgStartUP(event)">

                                   <mx:columns>

                                      <mx:Array>

                                         <mx:DataGridColumn dataField="fname"/>

                                         <mx:DataGridColumn dataField="lname"/>

                                      </mx:Array>

                                   </mx:columns>

                                </mx:DataGrid>

                            </mx:Component>

                         </mx:dropdownFactory>

                      </mx:ComboBox>