4 Replies Latest reply on Nov 13, 2008 10:22 AM by Newsgroup_User

    checkbox datagrid weird behaviour

    phil1943
      hello, I have a datagrid with an item rendered checkbox in one column.
      When the datagrid scrolls the checked items display incorrectly eg. items that should not be checked are, vice versa.
      The dataprovider for the datagrid is an array.

      Does anyone know how to overcome this problem ?

        • 1. Re: checkbox datagrid weird behaviour
          atta707 Level 2
          do you have custom renderer for this checkbox? can you show some code?
          • 2. checkbox datagrid weird behaviour
            phil1943 Level 1
            no, I dont have a custom renderer. I notice on the web others have had this same issue with checkboxes in datagrids.
            Can someone please advise on a good strategy to correct this odd behaviour.

            Here is what I have for the renderer in the column.

            <mx:DataGridColumn headerText="Delete" dataField="delete" width="50" rendererIsEditor="true" editable="false" editorDataField="selected">
            <mx:itemRenderer>
            <mx:Component>
            <mx:HBox horizontalAlign="center">
            <mx:CheckBox selected="false" click="outerDocument.checkBoxClick()" />
            </mx:HBox>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            • 3. Re: checkbox datagrid weird behaviour
              atta707 Level 2
              You'll need to 'bind' the selected property of the checkbox the the 'delete' attribute of each row:

              <mx:DataGridColumn headerText="Delete" dataField="delete" width="50" rendererIsEditor="true" editable="false" editorDataField="selected">
              <mx:itemRenderer>
              <mx:Component>
              <mx:HBox horizontalAlign="center">
              <mx:CheckBox selected="{data['delete']}" click="{outerDocument.checkBoxClick(); data['delete'] = !data['delete']}" />
              </mx:HBox>
              </mx:Component>
              </mx:itemRenderer>
              </mx:DataGridColumn>

              this would mean when item renderers are recycled they would pick up the right value for the current row. 'delete' attribute in the corresponding row in the dataProvider. Not the data['delete'] = !data['delete'] expression, this just toggles the value of the 'delete' attribute in the underlying dataProvider to keep you view and model in sync.

              For more information please look into Flex Builder Help on Custom Renderers and their life cycle.

              ATTA
              • 4. Re: checkbox datagrid weird behaviour
                Level 7

                "phil1943" <webforumsuser@macromedia.com> wrote in message
                news:gfgd2l$m66$1@forums.macromedia.com...
                > hello, I have a datagrid with an item rendered checkbox in one column.
                > When the datagrid scrolls the checked items display incorrectly eg. items
                > that
                > should not be checked are, vice versa.
                > The dataprovider for the datagrid is an array.
                >
                > Does anyone know how to overcome this problem ?

                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
                Q2