2 Replies Latest reply on May 17, 2006 8:33 AM by endquote

    problem with labelfunction with checkbox itemrenderer

    endquote
      I have a DataGrid with a column that looks like this:

      <mx:DataGridColumn headerText="Buy online?" dataField="onlineshop" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true" labelFunction="checkBoxLabel" editorDataField="selected" />

      My label function looks like this (for testing):

      private function checkBoxLabel(item:Object, column:Object):Boolean
      {
      return false;
      }

      The checkboxes in the grid always show up checked by default. What am I doing wrong?
        • 1. Re: problem with labelfunction with checkbox itemrenderer
          Level 7
          "endquote" <webforumsuser@macromedia.com> wrote in message
          news:e4e0cj$ffh$1@forums.macromedia.com...
          >I have a DataGrid with a column that looks like this:
          >
          > <mx:DataGridColumn headerText="Buy online?" dataField="onlineshop"
          > itemRenderer="mx.controls.CheckBox" rendererIsEditor="true"
          > labelFunction="checkBoxLabel" editorDataField="selected" />
          >
          > My label function looks like this (for testing):
          >
          > private function checkBoxLabel(item:Object, column:Object):Boolean
          > {
          > return false;
          > }
          >
          > The checkboxes in the grid always show up checked by default. What am I
          > doing
          > wrong?

          labelFunction is for the *label* (of the CheckBox, in this case). The
          selected property of the CheckBox is set based on the value of the
          dataField--in your case, "onlineshop". Is onlineshop true in all your items?

          --
          Manish Jethani
          Developer, Flex Framework
          Adobe Systems Inc.


          • 2. Re: problem with labelfunction with checkbox itemrenderer
            endquote Level 1
            In this case, "onlineshop" is always the string "0" (returned from an HTTPService), so it would make sense that would translate to a checked checkbox. I had thought that labelFunction would set the value of the editor specified in editorDataField.

            I've since gotten it working by using an inline cellRenderer instead of a drop-in one, though a drop-in one would make for simpler code.

            <mx:DataGridColumn headerText="Buy online?" dataField="onlineshop" rendererIsEditor="true" editorDataField="selected">
            <mx:itemRenderer>
            <mx:Component>
            <mx:CheckBox selected="{data.onlineshop == '1'}" click="data.onlineshop == selected ? '1' : '0'" />
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>

            Is there a simpler/better way?