2 Replies Latest reply on May 18, 2010 11:01 AM by nIvelyx

    Auto-Generate Checkboxes From DB?




      I'm wondering if anyone can point me in the right direction for auto-generating checkboxes in Flex. To give you an example of what I'm trying to accomplish, consider that I have a database table with 100 records. Each of those records can be "checkbox" items, so what I'd do traditionally (e.g. in CF/PHP/etc.) is simply loop over the values in the database and output them on the screen. Is there a way to accomplish this in Flex? I would prefer not to have to lay out every single checkbox item (using the Design view), unless absolutely necessary.


      Right now, I've got my checkbox values coming into Flex via an ArrayCollection (and of course, a remote call to my DB).


      If someone can give me an example of what I should be doing with the ArrayCollection in order to accomplish the aforementioned items (displaying all of these items as checkboxes on the page), it would be appreciated.



      Thank you

        • 1. Re: Auto-Generate Checkboxes From DB?
          David_F57 Level 5



          The following code will dynamically generate checkboxes from an arraycollection called myList, with the following 3 fields


          myList.description : String  <==== use this for the label

          myList.checked: boolean     <==== use this for the checked state

          myList.cb: object       <==== a Pointer to the checkbox



          protected function application1_creationCompleteHandler(event:FlexEvent):void


          for (var i:int=1; i < myList.length;i++)


          var cb:CheckBox = new CheckBox();



          cb.selected = myList[i].checked;

          cb.label = myList[i].description;


          myList[i].cb = cb;




          to access the values and update the array



          private function getCheckBoxValues(): void


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


             myList[i].checked = (myList[i].cb as CheckBox).selected;








          • 2. Re: Auto-Generate Checkboxes From DB?
            nIvelyx Level 1



            Thanks a bunch for your help.