2 Replies Latest reply on Oct 3, 2012 3:36 AM by sreekumar1976

    How to display data in ComboBox when click on DataGrid Row.

    sreekumar1976

      Hi!

       

           I am new to Adobe Flex. I am building one Project that was related to Comapny and Customer. First I created Company Master. Then I create Customer Master successfully and My Backkend is SQLite Database.

       

           My Problem is I have two files one is CustomerMaster and second one is CustomerForm.

       

           In CustomerMaster I have a datagrid in that data was displaying thru Array Collection. When ever we doublick on datagrid row it's displayed a CompanyForm. CompanyForm  contains TextFiled and ComboBox. TextFiled populating data but Combobox doesnot. It display always prompt message.

       

            Please help.

       

      Thanks,

      Sree Kumar

        • 1. Re: How to display data in ComboBox when click on DataGrid Row.
          Vibhuti Gosavi(InfoCepts) Level 3

          Hi Sree Kumar,

           

          Please have a look at this link , It will be helpful to you :

           

          http://www.actionscript.org/forums/showthread.php3?t=174947

           

           

          Thanks and Regards,

          ------------------------------------------------------------------------------------------ --

          Vibhuti Gosavi | vgosavi@infocepts.com | www.infocepts.com

          ------------------------------------------------------------------------------------------ --

          • 2. Re: How to display data in ComboBox when click on DataGrid Row.
            sreekumar1976 Level 1

            Hi! Vibhuti Gosavi,

             

                                  First of all thanks for your quick reply. Already I saw that link.

             

            Actually, In CustomerForm successfully store the information into the database. While retrieving the data problem cames. Sample Code:

             

            CustomerMaster:

             

            private function createItem():void

                                          {

                                                    openTab(new Object());

                                          }

                                          public function openTab(customer:Object):void

                                          {

                                                    var children:Array = tn.getChildren();

                                                    var length:int = children.length;

                                                    for (var i:int = 0; i<length; i++)

                                                    {

                                                              if (children[i].customer.customerId == customer.customerId)

                                                              {

                                                                        tn.selectedIndex = i;

                                                                        return;

                                                              }

                                                    }

             

                                                    var form:CustomerForm = new CustomerForm();

                                                    tn.addChild(form);

                                                    form.customer = customer;

                                                    form.dao = dao;

                                                    form.addEventListener(CustomerEvent.CREATE, customerChangeHandler),

                                                              form.addEventListener(CustomerEvent.UPDATE, customerChangeHandler),

                                                              form.addEventListener(CustomerEvent.DELETE, customerChangeHandler),

                                                              tn.selectedChild = form;

                                          }

             

                                          private function customerChangeHandler(event:CustomerEvent):void

                                          {

                                                    customerArrayList = dao.findByCustomerAll();

             

                                                    if (event.type == CustomerEvent.DELETE)

                                                    {

                                                              tn.removeChild(event.target as CustomerForm);

                                                    }

                                          }

             

             

                                ]]>

                      </fx:Script>

                      <mx:Canvas id="container" left="12" right="12" top="12" bottom="12">

                                <mx:Canvas left="0" top="2" right="0" height="33">

                                          <mx:Button id="AddCustomer" x="1" width="108" height="32" click="createItem()"

                                                                 icon="@Embed('assets/icon_plus.png')" label="Add Customer" toolTip="Add Customer"

                                                                 verticalCenter="-1"/>

                                </mx:Canvas>

                                <code:SuperTabNavigator id="tn" x="0" y="39" width="681" height="197"/>

                                <mx:DataGrid id="customerList" x="1" y="262" width="680" height="231"

                                                               dataProvider="{customerArrayList}"

                                                               doubleClick="openTab(customerList.selectedItem)" doubleClickEnabled="true">

                                          <mx:columns>

                                                    <mx:DataGridColumn dataField="customerId" headerText="Id"/>

                                                    <mx:DataGridColumn dataField="customerName" headerText="Name" />

                                                    <mx:DataGridColumn dataField="companyName" headerText="companyName" />

                                          </mx:columns>

                                </mx:DataGrid>

                      </mx:Canvas>

            CustomerForm:

             

            public function set customer(customer:Object):void

                                          {

                                                    this._customer = customer;

                                          }

                                          public function get customer():Object

                                          {

                                                    return this._customer;

                                          }

                                          private function saveCustomer():void

                                          {

                                                    if (Validator.validateAll(customerValidators).length>0)

                                                    {

                                                              return;

                                                    }

                                                    _customer.customerName = customerName.text;

                                                     _customer.companyName = companyName.text;

             

                                                    if (_customer.customerId > 0)

                                                    {

                                                              updateCustomer();

                                                    }

                                                    else

                                                    {

                                                              insertCustomer();

                                                    }

                                          }

                                          private function insertCustomer():void

                                          {

                                                    try

                                                    {

                                                              Alert.show(_customer.normalPkts);

                                                              dao.insertCustomer(_customer);

                                                              customerId.text = _customer.customerId;

                                                              dispatchEvent(new CustomerEvent(CustomerEvent.CREATE, _customer, true));

                                                              var alertText:String="Company Created Successfully!";

                                                              Alert.show(alertText,"",4,null,null,ConfirmMessage);

                                                    }

                                                    catch (error:SQLError)

                                                    {

                                                              var alertErrorCreate:String="Company not Created...";

                                                              Alert.show(alertErrorCreate+"\n"+error.details,"",4,null,null,ErrorMessage);

                                                    }

                                          }

                                          private function updateCustomer():void

                                          {

                                                    try

                                                    {

                                                              dao.updateCustomer(_customer);

                                                              dispatchEvent(new CustomerEvent(CustomerEvent.UPDATE, _customer, true));

                                                              var alertText:String="Company Updated Successfully!";

                                                              Alert.show(alertText,"",4,null,null,ConfirmMessage);

                                                    }

                                                    catch (error:SQLError)

                                                    {

                                                              var alertErrorText:String="Company not Updated...";

                                                              Alert.show(alertErrorText+"\n"+error.details,"",4,null,null,ErrorMessage);

                                                    }

                                          }

                                          private function deleteItem():void

                                          {

                                                    try

                                                    {

                                                              dao.deleteCustomer(_customer);

                                                              dispatchEvent(new CustomerEvent(CustomerEvent.DELETE, _customer, true));

                                                    }

                                                    catch (error:SQLError)

                                                    {

                                                              Alert.show(error.details, "Error");

                                                    }

                                          }

                                ]]>

                      </mx:Script>

               <mx:Grid x="10" y="10" width="665" height="130" verticalAlign="middle">

                                <mx:GridRow width="665" height="100%">

                                          <mx:GridItem width="85" height="100%">

                                                    <mx:Label width="85" text="Customer Id:"/>

                                          </mx:GridItem>

                                          <mx:GridItem width="115" height="100%">

                                                    <mx:TextInput id="customerId" text="{_customer.customerId}" editable="false" width="115"/>

                                          </mx:GridItem>

                                          <mx:GridItem width="102" height="100%">

                                                    <mx:Label width="102" text="Company Name:"/>

                                          </mx:GridItem>

                                          <mx:GridItem width="100" height="100%">

                                                    <mx:ComboBox id="companyName" dataProvider="{companyIdList}" labelField="companyName"

                                                                                   prompt="Select..." text="{_customer.companyName}" width="100"/>

                                          </mx:GridItem>

                                  <mx:GridItem width="230" height="100%" horizontalAlign="center" verticalAlign="middle">

                                                    <mx:Button label="Save" click="saveCustomer()"/>

                                                    <mx:Button label="Delete" click="deleteItem()"/>

                                          </mx:GridItem>

                                </mx:GridRow>

                      </mx:Grid>

            =====================================================================

             

            I have two ArrayCollections 1) companyIdList (CustomerForm)

                                                      2) customerArrayList(CustomerMaster)

             

            please go through the bold text. Please focus on two dataProviders. These dataproviders are binding for One Combo Field.

             

            Thanks,

            Sree Kumar

             

             

             

             

             


             

            Message was edited by: sreekumar1976