5 Replies Latest reply on Jul 23, 2007 11:08 AM by ntsiii

    Putting Checkboxes inside a list

    africanshox
      ive downloaded this sample from http://blogs.adobe.com/aharui/

      and im tryin to use it in my course management application.

      im using amfphp 1.9


      i simply want the app to retrieve the list of courses available and populate a list which will the be used in a form so that a student can be enrolled onto a course by clicking on a checkbox. similar to the sample shown above.


      the courses table contains the following fields

      CourseID
      CourseName
      TeacherID

      below is a break down of my code hope it makes sense

      populating the array collection:

      courseList = new ArrayCollection ( ArrayUtil.toArray(evt.result) );



      layout:
      <mx:Label x="21" y="290" text="Course"/>
      <mx:List id="list1" dataProvider="{courseList}" width="242" x="21" y="307" labelField="CourseName" height="138">

      </mx:List>

      my list currently shows all the courses from the courses table, however i want to attach a checkbox to each list.

      the list will be used in a form which allows the user to select what courses to enrol the student to. im not sure how to exactly

      so how can i get my check boxes to behave in the same way as the sample application shown on the links above?
        • 1. Re: Putting Checkboxes inside a list
          jlingwai Level 1
          add a check boxes as an itemrenderer to the list
          • 2. Putting Checkboxes inside a list
            Dzihan Level 1
            I did that and faced this behaviour:

            When checking checkboxes in the list, scroll down to make them disappear to the top and then scroll up to let them reappear they are unchecked?!
            thats pretty strange...

            Another thing is, how can i access the single checkbox objects to see if they are checked or not?
            • 3. Re: Putting Checkboxes inside a list
              africanshox Level 1
              i get the same issue as above as well can anyone help as to what the best solution for accessing a component thats inside an item renderer is?
              • 4. Re: Putting Checkboxes inside a list
                JKohn99 Level 1
                This works fine for me and I have no scrolling issues. My item renderer is copied below. The data property is a custom object that supports a _selected attribute.
                So to fill the list I create objects to populate the list and create any array collection. This then is the dataprovider for the list.

                To determine if an item is checked I iterate the collection and examine the selected attribute.

                -------------------------------------------
                Item rendererer
                ----------------------------------------------
                <?xml version="1.0"?>
                <!-- itemRenderers\list\myComponents\RendererState.mxml -->
                <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="120" height="20">
                <mx:Script>
                <![CDATA[
                private function doSelection():void
                {
                if(cb.selected == true)
                data.selected = true;
                else
                data.selected = false;
                }
                ]]>
                </mx:Script>

                <!-- Define the Link control to open a URL. -->
                <mx:CheckBox id="cb" click="doSelection()" selected="{data.selected}" width="17"/>
                <mx:Label id="State" text="{data.label}" x="17" y="0" width="90"/>
                </mx:Canvas>
                ------------------------------------------------------------------------------------------ --
                • 5. Re: Putting Checkboxes inside a list
                  ntsiii Level 3
                  Are you sure that works? "data" is not a proerty of mx:Canvas.

                  The "prefered" way to get the data in a component renderer is to override the setter:

                  public function override set data(data:Object):void {

                  Here is an example fo a checkbox renderer that handles scrolling correctly:
                  http://www.cflex.net/showFileDetails.cfm?ObjectID=559&ChannelID=1

                  Tracy