1 Reply Latest reply on Jul 23, 2009 4:46 AM by ma.tze

    database driven combobox itemrenderer in DataGrid

    ma.tze Level 1

      Hi

       

      I created a database driven combobox itemrenderer, code see below:

       

      The data is loaded and shown correctly, but when I change the combobox, suddenly a "0" appears:

      I can see in the debugger in combobox1_changeHandler, that the correct data is taken from the combo "this.selectedItem.data=3;" and written to "data.professionGroup", (changed from "1" to "3")

      but then when the code jumps to set data the "value.professionGroup" is "0"?!?!

       

      Thank yor for any pointers!

       

      The DataGrid:

          <mx:DataGrid id="personDg" dataProvider="{sm.persons}" width="100%" height="100%" editable="true">
              <mx:columns>

                  <mx:DataGridColumn headerText="firstName" dataField="firstName"/>
                  <mx:DataGridColumn headerText="lastName" dataField="lastName"/>
                  <mx:DataGridColumn headerText="professionGroup" dataField="professionGroup" editable="true" editorDataField="data"
                      rendererIsEditor="true"
                      itemRenderer="com.xxx.view.components.combobox.ProfessionGroupCombo">
                  </mx:DataGridColumn>

              </mx:columns>
          </mx:DataGrid>

       

      The ItemRenderer:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:ComboBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"
          change="combobox1_changeHandler(event)"  initialize="combobox1_initializeHandler(event)" >
          
              <fx:Script>
                  <![CDATA[
                      import mx.controls.dataGridClasses.DataGridListData;
                      import com.myfim.model.ShellModell;
                        import mx.events.ListEvent;
                         import mx.events.FlexEvent;
                    
                      [Bindable]
                      private static var sm:ShellModell=ShellModell.getInstance();

         
                         public function setSelectedItemByValue(val:int):void{                                                                   
                              this.selectedIndex = -1; // Show prompt if value is not found
                              for (var i:int=0;i<this.dataProvider.length;i++){

                                  if(this.dataProvider[i].data == val){
                                      this.selectedIndex = i;
                                      break;
                                  }
                              }// for
                      }
                     
                      override public function set data(value:Object):void{

                          super.data=value; // value is the VO!
                          setSelectedItemByValue(value.professionGroup);
                      }                
                     
                      protected function combobox1_changeHandler(event:ListEvent):void
                      {

                          data.professionGroup=this.selectedItem.data;                   
                          // I can see in the debugger that "data.professionGroup" gets the correct data f.e. ="3" , but if it jumps to the "set data" the                          value.professionGroup is "0" !??     

                          }

       

                      protected function combobox1_initializeHandler(event:FlexEvent):void
                      {

                          this.dataProvider=sm.comboData.professionGroupAc;  // AC of (label, data)
                      }
                  ]]>
              </fx:Script>
      </mx:ComboBox>