9 Replies Latest reply on Aug 1, 2007 1:59 PM by dimival

    Using checkbox as ItemEditor fails

    dimival Level 1
      I am trying to use a CheckBox as an itemEditor inside a DataGrid so i am doing this:

      <mx:DataGridColumn dataField="idDoctoEnvio" headerText=" " itemEditor="mx.controls.CheckBox" editorDataField="selected" editable = "true"/>

      I read in the developer's guide that this is the way to do it, so i tried it and to my surprise, it doesn't work, i menan there is no CheckBox control inside the datagrid, instead there is a normal text value (true or false).

      Any ideas on how to do this? I need the checkbox to be able to change that property from true to false and viceversa
        • 1. Re: Using checkbox as ItemEditor fails
          jpwrunyan Level 1
          I reported this problem to Adobe last year. From your other post, I assume you already got the upgrade and so I further assume they didn't fix it. Nice to see they are listening.
          Long story short, you can't use CheckBox as an itemRenderer/itemEditor. It just doesn't work as promised. What I did was I developed my own CheckBox item renderer class (I put the CheckBox component inside an HBox so that I could also center it in the cell). With the appropriate logic, it works fine. I made this component a long time ago and the source is not on this computer, but I think the problem was related to the CheckBox not updating its selected property in accordance with the background data. In my component, I set the CheckBox's selected value to update according to the "dataChange" event and on the CheckBox's "change" event, I called a method to update the data["columnName"] value so that it matches the CheckBox's selected value. I think this will do the trick. The code is probably still archived in this forum somewhere.
          • 2. Re: Using checkbox as ItemEditor fails
            dimival Level 1
            Thanks for you reply, i am now trying this, using a VBox with a CheckBox inside:

            <mx:DataGridColumn dataField="idDoctoEnvio" headerText=" " editable="true" rendererIsEditor="true" itemEditor="com.legosoft.mxml.ItemEditorCheckBox" editorDataField="cbSelected" width="45"/>

            where ItemEditorCheckBox is:

            <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml">
            <mx:CheckBox id="editorCB" height="100%" width="100%" selected="{data.FollowUp}"
            click="cbSelected=editorCB.selected" updateComplete="cbSelected=editorCB.selected;"/>

            <mx:Script>
            <![CDATA[
            [Bindable]
            public var cbSelected : Boolean;
            ]]>
            </mx:Script>
            </mx:VBox>

            And still doesn't work!!!!
            HELP please!!!
            • 3. Re: Using checkbox as ItemEditor fails
              jpwrunyan Level 1
              Ok, although I completely hold Adobe responsible for not implementing the CheckBox component properly, you do need to take it upon yourself to read the documentation first before asking for further help. I had this same problem and had to work through it myself (although I did get some help from the LiveDocs guys for tab focusing). The way I did that was I read the documentation on creating item editors and consulted the API's for the appropriate interfaces--something I can tell from your code that you haven't done yet. Do that first. Then if you still have problems, come back with your new, more accurately implemented code. I don't want you to think I am picking on you. It's just that by investing a little more effort this way, my life will be easier and yours will be improved.
              • 4. Using checkbox as ItemEditor fails
                dimival Level 1
                So a RTFM is the answer that you are going to give me, well then.

                You say your life would be easier and mine improved? what is that supposed to mean? if posting here causes you so much trouble in your life, then don't and your life would be a lot easier.

                • 5. Re: Using checkbox as ItemEditor fails
                  chris.huston.t10 Level 3
                  Here is the code I use for putting checkboxes in a datagrid column:

                  <mx:DataGridColumn textAlign="center" width="70" headerText="Active" dataField="active">
                  <mx:itemRenderer>
                  <mx:Component>
                  <mx:HBox horizontalAlign="center" paddingLeft="10">
                  <mx:CheckBox click="data.active = outerDocument.toggle_course(data);" selected="{Boolean(int(data.active))}"/>
                  </mx:HBox>
                  </mx:Component>
                  </mx:itemRenderer>
                  </mx:DataGridColumn>

                  The outerDocument.toggle_course(data) is used to call the function in the main application that manages the change in the checkbox state. outerDocument is necessary because the component does not have scope to call the application functions directly.

                  I hope this helps.

                  Vygo
                  • 6. Re: Using checkbox as ItemEditor fails
                    jpwrunyan Level 1
                    quote:

                    Originally posted by: jpwrunyan
                    The way I did that was I read the documentation on creating item editors and consulted the API's for the appropriate interfaces--something I can tell from your code that you haven't done yet. Do that first. Then if you still have problems, come back with your new, more accurately implemented code. I don't want you to think I am picking on you. It's just that by investing a little more effort this way, my life will be easier and yours will be improved.


                    I will paraphrase the above:

                    "Give a man a fish; feed him for a day. Teach a man to fish; feed him for a lifetime."
                    • 7. Re: Using checkbox as ItemEditor fails
                      dimival Level 1
                      Thanks Masamune that worked perfectly, i think i see what my mistake was, but thanks a lot :)
                      • 8. Re: Using checkbox as ItemEditor fails
                        GeorgeWS Level 1
                        Do You have complete code example? I am stumped and frustrated. 3 days for a simple checkbox that works.
                        • 9. Using checkbox as ItemEditor fails
                          dimival Level 1
                          <mx:DataGridColumn dataField="idDoctoEnvio" headerText=" DocEnv" editable="true" width="45">
                          <mx:itemRenderer>
                          <mx:Component>
                          <mx:HBox horizontalAlign="center" paddingLeft="10">
                          <mx:CheckBox selected="{data.idDoctoEnvio}" click="data.idDoctoEnvio=!(data.idDoctoEnvio) />
                          </mx:HBox>
                          </mx:Component>
                          </mx:itemRenderer>
                          </mx:DataGridColumn>


                          Where idDoctoEnvio is the property of the objects in my dataProvider that is binded to the checkbox