9 Replies Latest reply on Jan 3, 2011 2:09 AM by tvendhan

    Need help on selectedIndex Property

    tvendhan

      Hi,

       

      We are facing a issue in our screen which is developed using Flex Builder 3.0.

       

      We have Extended the Functionality of "AdvancedDataGridColumn.as" to have List of Values(LOV) editable column in it. User can add rows to the Advanced Data Grid  by Clicking on "Add Row" button.

       

      Actual Scenario of the problem is, When the user adds two empty rows and then enters the search crtiteria in the first row. After entering the search criteria in the first row user accidently clicks the second row. Here second row is getting populated with values whereas first row remains as it is.

       

      We understood that after clicking the second row, Second row becomes the active row. This is the actual cause for this issue.

       

      Please suggest us a solution to fix this issue.

       

      Thanks in Advance.

        • 1. Re: Need help on selectedIndex Property
          flex2008 Level 3

          Pls post the code where in which you are saving the data,which then leads to getting populated in the wrong row.

          • 2. Re: Need help on selectedIndex Property
            drkstr_1 Level 4

            The chances of someone finding the error in your code are a lot better if you post some.

             

            *edit*

             

            I was ninja'd

            • 3. Re: Need help on selectedIndex Property
              tvendhan Level 1

              Here is the code.

               

              MXML Part:

               

              1. eventExSelectHandler function

               

                   public function eventExSelectHandler(event:EventEx):void
                   {
                    cslovAC.getItemAt(adgMailTo.selectedIndex).csInChargeCode = event.params.CsInChargeCode;
                    cslovAC.getItemAt(adgMailTo.selectedIndex).csInCharge     = event.params.CsInCharge;
                    cslovAC.getItemAt(adgMailTo.selectedIndex).csMailAddress  = event.params.EmailAddress;
                    cslovAC.getItemAt(adgMailTo.selectedIndex).csCsInChargeId = event.params.CsInChargeId;
                   }

               

              2. Layout Part

               

              <lovDG:AdvancedLOVDataGridEx x="183" y="554" id="adgMailTo" designViewDataType="flat" width="731" height="90"  verticalScrollPolicy="on" visible="{japButton.selected}" dataProvider="{cslovAC}" tabIndex="13" editable="true" mouseFocusEnabled="false">
                  <lovDG:columns>

                        <lovColumn:AdvancedDataGridLOVColumn
                       headerText="担当CSコード" textAlign="left" width="150" rendererIsEditor="true"
                       dataField="csInChargeCode" lovClassification="{LOVConstants.CLASS_MAIL_TO}"
                       maxBytes="10" imeOff="true" editable="true" id="adgcMailToEmpNo"
                       eventExSelect="{eventExSelectHandler(event)}" headerWordWrap="true"
                       />

               

                   <lovColumn:AdvancedDataGridLOVColumn
                       headerText="担当CS" textAlign="left" width="230" rendererIsEditor="true"
                       dataField="csInCharge" lovClassification="{LOVConstants.CLASS_MAIL_TO1}"
                       maxBytes="40" imeMode="{IMEConversionMode.JAPANESE_HIRAGANA}" editable="true" id="adgcMailToEmpName"
                       eventExSelect="{eventExSelectHandler(event)}" headerWordWrap="true"
                       />

                   <ctc:AdvancedDataGridColumnEx headerText="メールアドレス" dataField="csMailAddress" id="adgcMailToAddress" textAlign="left" editable="true"      itemEditor="{new ClassFactory(scripts.AdvancedDataGridMailInput)}" headerWordWrap="true"

              />
                   <ctc:AdvancedDataGridColumnEx headerText="チャージにCSのID" dataField="csCsInChargeId" id="adgcCsInChargeId" visible="false"/>

               

                  </lovDG:columns>
                 </lovDG:AdvancedLOVDataGridEx>

               

              Actionscript Part

               

              package components.lov.advancedDataGridClasses
              {
              import components.lov.LOVConstants;
              import components.lov.renderers.LovInputExItemRenderer;

              import jp.co.ctcg.as3.controls.advancedDataGridClasses.AdvancedDataGridColumnEx;
              import jp.co.ctcg.as3.events.EventEx;

              import mx.core.ClassFactory;

              /**
              * AdvancedDataGridColumnのLOV版クラス.
              * @see mx.controls.advancedDataGridClasses.AdvancedDataGridColumn
              * @see jp.co.ctcg.xxscm_qotsbcn.common.components.LOVInputEx
              */
              //--------------------------------------
              //  Events
              //--------------------------------------

              /**
              * データを選択された時のイベント.
              */
              [Event(name="eventExSelect", type="jp.co.ctcg.as3.events.EventEx")]

              /**
              * 空データの状態でフォーカスアウトした時のイベント.
              */
              [Event(name="eventEmptyFocusOut", type="jp.co.ctcg.as3.events.EventEx")]

              public class AdvancedDataGridLOVColumn extends AdvancedDataGridColumnEx
              {
              private var lovRenderer:ClassFactory;
              private var properties:Object;

              //--------------------------------------------------------------------------
              //
              //  Class properties
              //
              //--------------------------------------------------------------------------

              //--------------------------------------------------------------------------
              //
              //  Constructor
              //
              //--------------------------------------------------------------------------


              /**
                * コンストラクタ.
                * @param columnName
                *
                */
              public function AdvancedDataGridLOVColumn(columnName:String=null)
              {
                super(columnName);
                rendererIsEditor = true;

                lovRenderer = new ClassFactory(LovInputExItemRenderer);
                itemRenderer = lovRenderer;

                properties = new Object();
                lovRenderer.properties = properties;

                this.addEventListener("eventExSelectRow", eventExSelectHandler);
                this.addEventListener("eventEmptyFocusOutRow", eventEmptyFocusOutHandler);

              }

              //--------------------------------------------------------------------------
              //
              //  Properties
              //
              //--------------------------------------------------------------------------

              //----------------------------------
              // lovClassification
              //----------------------------------
              private var _lovClassification:String;//LOV種別

              /**
                * LOV種別プロパティ.
                * @param value
                *
                */
              public function get lovClassification():String
              {
                return _lovClassification;
              }

              public function set lovClassification(value:String):void
              {
                _lovClassification = value;
                _hideConditional = LOVConstants.HIDE_CONDITIONAL_ITEM[(int((Number(value))))];
                properties["lovClassification"] = value;
                properties["hideConditional"] = _hideConditional;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              // otherData
              //----------------------------------
              private var _otherData:Object; //選択された。他その他のデータ

              /**
                * その他のデータ.
                * @param value
                *
                */
                  [Bindable("eventExSelectRow")]
                  [Inspectable(environment="none")]
              public function get otherData():Object
              {
                return _otherData;
              }

              public function set otherData(value:Object):void
              {
                _otherData = value;
                properties["otherData"] = _otherData;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              // hideConditional
              //----------------------------------
              private var _hideConditional:Object;

              /**
                * 隠し条件項目(Java側HashMap).
                * @param val Java側HashMap
                *
                */
              public function get hideConditional():Object
              {
                return _hideConditional;
              }

              public function set hideConditional(val:Object):void
              {
                _hideConditional = val;
                properties["hideConditional"] = val;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              // prefix
              //----------------------------------
              private var _prefix:String = "";//接頭語

              /**
                * 接頭語.
                *
                */
              public function get prefix():String
              {
                return _prefix;
              }

              public function set prefix(value:String):void
              {
                _prefix = value;
                properties["prefix"] = _prefix;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              //  required
              //----------------------------------
              [Bindable]
              private var _required:Boolean = false;

              private var requiredChanged:Boolean = false;
              /**
                * 必須項目の場合に指定します.背景色が黄色になります.
                *
                * @param value true:背景色黄色,false:背景色白色.
                *
                */
              public function get required():Boolean
              {
                return _required;
              }

              /**
                * @private
                */
              public function set required(value:Boolean):void
              {
                _required = value;
                properties["required"] = _required;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              //  maxBytes
              //----------------------------------
              private var _maxBytes:int = -1;
              /**
                * 入力できるbyte数の上限.
                *
                * @default -1
                */
              public function get maxBytes():int
              {
                return _maxBytes;
              }

              /**
                * @private
                */
              public function set maxBytes(val:int):void
              {
                _maxBytes = val;
                properties["maxBytes"] = _maxBytes;
                lovRenderer.properties = properties;
              }

              //----------------------------------
              //  imeOff
              //----------------------------------
              private var _imeOff:Boolean = false;

              /**
                * 日本語変換させない設定.
                * @param val
                *
                */
              public function get imeOff():Boolean
              {
                return _imeOff;
              }

              /**
                * @private
                */
              public function set imeOff(val:Boolean):void
              {
                _imeOff = val;
                properties["imeOff"] = _imeOff;
                lovRenderer.properties = properties;
              }

              //--------------------------------------------------------------------------
              //
              //  Event handlers
              //
              //--------------------------------------------------------------------------
              protected function eventExSelectHandler(event:EventEx):void
              {
                dispatchEvent(new EventEx("eventExSelect", event.params, false, false));
              }

              protected function eventEmptyFocusOutHandler(event:EventEx):void
              {
                dispatchEvent(new EventEx("eventEmptyFocusOut", event.params, false, false));
              }

              //----------------------------------
              //  imeMode
              //----------------------------------
              private var _imeMode:String = null;

              /**
                * 日本語変換させない設定.
                * @param val
                *
                */
              override public function get imeMode():String
              {
                return _imeMode;
              }

              /**
                * @private
                */
              override public function set imeMode(val:String):void
              {
                _imeMode = val;
                properties["imeMode"] = _imeMode;
                lovRenderer.properties = properties;
              }
              }
              }

              • 4. Re: Need help on selectedIndex Property
                flex2008 Level 3

                I have a couple of questions:

                 

                1)When is this otherData set?
                2)What are the contents of params in EventEx?

                 

                Pls post the relevant code for the above two to get a better understanding.

                • 5. Re: Need help on selectedIndex Property
                  tvendhan Level 1

                  Here are the answers:

                   

                  1) I am not using OtherData property in MXML. It is just defined in ActionScript and not used anywhere in MXML.

                   

                  2) EventEx has 4 parameters (4 Columns) csInChargeCode,csInCharge,csMailAddress and csCsInChargeId. You can very well see this four columns in Advanced Data Grid MXML part. User can select either csInChargeCode or csInCharge and depending on the selected value all the other fields will be populated.

                   

                  Thanks.

                  • 6. Re: Need help on selectedIndex Property
                    flex2008 Level 3

                    Is it possible to post the full code,but with just one column where the issue can be reproduced?.I find it difficult to make out the reason from this.I assume it has got something to do with the place where you are dispatching eventExSelectRow event

                    • 7. Re: Need help on selectedIndex Property
                      tvendhan Level 1

                      Hi,

                       

                      We are using EventEx functionality to Select Corresponding Values of csInChargecode or csInCharge which user can select from LOV.

                       

                      csInChargeCodecsInChargecsMailAddresscsCsInChargeId

                      LOV Column, If selects csInChargeCode all the other three columns will be populated with corresponding values

                      LOV ColumnNon-LOV Columnhidden Non-LOV column.
                      LOV ColumnLOV Column, If selects csInCharge all the other three columns will be populated with corresponding values

                       

                      // ActionScript of EventEx

                       

                      package jp.co.ctcg.as3.events
                      {
                      import flash.events.Event;


                      public class EventEx extends Event
                      {
                      //--------------------------------------------------------------------------
                      //
                      //  Class constants
                      //
                      //--------------------------------------------------------------------------

                      public static const EVENT_EX:String = "eventEx";

                       

                      public static const EVENT_SELECT:String = "eventExSelect";

                       

                      public static const EVENT_CLOSE:String = "eventExClose";

                       

                      public static const EVENT_OK:String = "eventExOk";


                      public static const EVENT_CANCEL:String = "eventExCancel";

                       

                      public static const EVENT_CHANGE:String = "eventExChange";

                      //--------------------------------------------------------------------------
                      //
                      //  Constructor
                      //
                      //--------------------------------------------------------------------------


                      public function EventEx(type:String, params:Object=null , bubbles:Boolean=false, cancelable:Boolean=false)
                      {
                        super(type, bubbles, cancelable);

                        this.params = params;
                      }

                      //--------------------------------------------------------------------------
                      //
                      //  Variables
                      //
                      //--------------------------------------------------------------------------

                       

                      public var params:Object;

                      //--------------------------------------------------------------------------
                      //
                      //  Overridden methods
                      //
                      //--------------------------------------------------------------------------


                      override public function clone():Event
                      {
                        return new EventEx(type, params, bubbles, cancelable);
                      }
                      }
                      }

                       

                      Thanks.

                      • 8. Re: Need help on selectedIndex Property
                        flex2008 Level 3

                        Still I cant find the portion where u are dispatching the eventExSelectRow event.Pls post the complete mxml code.

                        • 9. Re: Need help on selectedIndex Property
                          tvendhan Level 1

                          Hi,

                           

                          Event Dispatching is not done in MXML, It is done in "AdvancedDataGridLOVColumn.as" which was posted already. I am posting that part alone again.


                          //------------------------------------------------------------------- -----------------------------------
                          //
                          //  Event Dispatch handlers (in AdvancedDataGridLOVColumn.as)
                          //
                          //------------------------------------------------------------------- ----------------------------------
                          protected function eventExSelectHandler(event:EventEx):void
                          {
                            dispatchEvent(new EventEx("eventExSelect", event.params, false, false));
                          }

                          protected function eventEmptyFocusOutHandler(event:EventEx):void
                          {
                            dispatchEvent(new EventEx("eventEmptyFocusOut", event.params, false, false));
                          }

                           

                          MXML Part:

                           

                          1) eventExSelectHandler function

                           

                               public function eventExSelectHandler(event:EventEx):void
                               {
                                cslovAC.getItemAt(adgMailTo.selectedIndex).csInChargeCode = event.params.CsInChargeCode;
                                cslovAC.getItemAt(adgMailTo.selectedIndex).csInCharge     = event.params.CsInCharge;
                                cslovAC.getItemAt(adgMailTo.selectedIndex).csMailAddress  = event.params.EmailAddress;
                                cslovAC.getItemAt(adgMailTo.selectedIndex).csCsInChargeId = event.params.CsInChargeId;
                               }

                           

                          2) Assigning the above eventExSelectHandler to the AdvancedDataGridLOV Column.

                           

                             <lovColumn:AdvancedDataGridLOVColumn
                                   headerText="担当CSコード" textAlign="left" width="150" rendererIsEditor="true"
                                   dataField="csInChargeCode" lovClassification="{LOVConstants.CLASS_MAIL_TO}"
                                   maxBytes="10" imeOff="true" editable="true" id="adgcMailToEmpNo"
                                   eventExSelect="{eventExSelectHandler(event)}" headerWordWrap="true"
                                   />

                           

                          Actual flow:

                          AdvancedDataGridLOVColumn.as ---> Imported EventEx.as (Has two Event Dispatchers in it) ---> MXML has a eventExSelectHandler as mentioned above

                          ---> eventExSelectHandler was assigned to "eventExSelect" property of AdvancedDataGridLOVColumn.

                           

                          Thanks.