3 Replies Latest reply on Apr 20, 2009 10:17 AM by GeorgeWS

    Checkbox binding to a Datagrid

    GeorgeWS Level 1

      I have a DG filled by a RO. when a row gets pressed some form fields get filled in. Perfect. I have some check boxs that I also want to change to checked or not according to the data. my SQL table has "true" or "false". Its like this:

       

       

      public function itemClicked(event:ListEvent):void
         {
        ID.text = mainList.selectedItem.ID;
              Vin.text = mainList.selectedItem.Vin;

              drcheck.selected = mainList.selectedItem.DrCheck;
              pscheck.selected = mainList.selectedItem.PsCheck;

       

         }

       

       

       

      <mx:DataGrid id="mainList" width="100%" dataProvider="{vehicleList}" itemClick="itemClicked(event)" height="100%"  >
                   <mx:columns>
                       <mx:DataGridColumn headerText="Vin" dataField="Vin"/>
                   </mx:columns>
               </mx:DataGrid>

       

       

      <mx:FormItem id="idFormItem" includeInLayout="false" visible="false">
          <mx:TextInput id="ID" includeInLayout="false" visible="false"/>
         </mx:FormItem>
         <mx:HBox width="100%">
                  <mx:Label text="Vin" width="72"/>
                  <mx:FormItem  id="VinFormItem" width="150" themeColor="#73B9B9">
          <mx:TextInput id="Vin"/>
         </mx:FormItem>
         </mx:HBox>

       

       

      <mx:CheckBox label="Pending" id="drcheck" themeColor="#73B9B9"/>

      <mx:CheckBox label="Pending" id="pscheck" themeColor="#73B9B9"/>

       

      The checkboxs never seem to change, but if I us an Alert to show me What this is when I press in the datagrid: mainList.selectedItem.DrCheck

      It shows a true or false works good. How can I get that to change the checkbox. This should be so easy.

       

      Thanks

      G

        • 1. Re: Checkbox binding to a Datagrid
          Michael Borbor Level 4

          Have you try casting this:

          Boolean(mainList.selectedItem.DrCheck)
          

          I think the problem is the conversion that occurrs when the object gets converted between flex and your RO. Try debuggin to see how the data is coming back from your server.

          • 2. Re: Checkbox binding to a Datagrid
            Gregory Lafrance Level 6

            I think this is necessary:

             

            drcheck.selected = mainList.selectedItem.DrCheck == "true" ? true : false;
            pscheck.selected = mainList.selectedItem.PsCheck == "true" ? true : false;

             

            Its because the data is treated as strings.

            • 3. Re: Checkbox binding to a Datagrid
              GeorgeWS Level 1

              Thanks, that worked, sort of. I ended up having to do a cfset in my cfc to convert the YES or No to a true false. What a pain. So now that I got the data base getting the slection from the checkbox, I want to do an update to the ArrayCollection. I am doing this:

               

              var currentlySelectedItem : Object = mainList.selectedItem;
                        currentlySelectedItem.Vin =  Vin.text;
                        currentlySelectedItem.BrandID =  BrandID.text;
                        currentlySelectedItem.BrandID2 =  BrandID2.text;
                        currentlySelectedItem.drcheck =  drcheck.selected;
                        currentlySelectedItem.pscheck =  pscheck.selected;
                        vehicleList.itemUpdated(currentlySelectedItem);

               

              The Vin works when I change the Vin, update the database the AC gets updated and when I click off that vin and to another and back the update stays. So thats good. My problem is with the BrandID, BrandID2 these are RO filled Comboboxs that do not get updated and back to my original part the checkboxs do not get updated. The DB updates but the AC does not. Any thoughts?

               

              Thanks