5 Replies Latest reply on Jul 1, 2008 12:34 PM by travisdh1

    can't make checkbox  in datagrid uneditable

    gw789
      This is a sample from the flex documentation. I added editable="false" to the stepper and the checkbox columns. The checkbox still changes if you click it!! I want this column to be display only. Any ideas?

      <?xml version="1.0"?>
      <!-- itemRenderers\inline\CBInlineCellEditor.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[



      import mx.collections.ArrayCollection;

      [Bindable]
      private var myDP:ArrayCollection = new ArrayCollection([
      {label1:"Order #2314", contact:"John Doe",
      quant:3, solddate:new Date(2005, 0, 1), Sent:true},
      {label1:"Order #2315", contact:"Jane Doe",
      quant:3, solddate:new Date(2005, 0, 5), Sent:false}
      ]);
      private function checkCheck(e:Event):void {
      trace("edited");

      }

      ]]>
      </mx:Script>

      <mx:DataGrid id="myDG"
      dataProvider="{myDP}"
      variableRowHeight="true" itemEditEnd="checkCheck(event)"
      width="500" height="250"
      editable="true">
      <mx:columns>
      <mx:DataGridColumn dataField="label1"
      headerText="Order #"
      editable="false"/>
      <mx:DataGridColumn dataField="quant"
      headerText="Quantity"
      editable = "false"
      itemEditor="mx.controls.NumericStepper"
      editorDataField="value"/>
      <mx:DataGridColumn dataField="solddate"
      headerText="Date"
      itemRenderer="mx.controls.DateField"
      rendererIsEditor="true"
      editorDataField="selectedDate"/>
      <mx:DataGridColumn dataField="Sent"
      itemRenderer="mx.controls.CheckBox"
      rendererIsEditor="true"
      editable = "false"
      editorDataField="selected"/>
      </mx:columns >
      </mx:DataGrid>
      </mx:Application>

        • 1. Re: can't make checkbox  in datagrid uneditable
          Suren_kancherla Level 1
          Hello,
          I think CheckBox click event is still working on even you say editable=false. So create ItemRender as separate component and add this ActionScript it might stops your checkbox toggling.

          <mx:DataGridColumn dataField="Sent" itemRenderer="com.MyCheckBox" editable = "false"/>


          <!-- com.MyCheckBox.mxml -->

          <?xml version="1.0" encoding="utf-8"?>
          <mx:CheckBox xmlns:mx=" http://www.adobe.com/2006/mxml" click="toggle()">
          <mx:Script>
          <![CDATA[
          private function toggle():void {
          if(this.selected==true)
          this.selected = false;
          else
          this.selected = true;
          }
          ]]>
          </mx:Script>
          </mx:CheckBox>
          • 2. Re: can't make checkbox  in datagrid uneditable
            gw789 Level 1
            It gives the following error: "Overriding a function that is not marked for override." So I changed the function name ( and click =) to mytoggle. It does what I need, thank you. However, this doesn't work when I set editable to true. I'm just curious. As I said, the solution we have is all I need for now, thanks again..
            • 3. Re: can't make checkbox  in datagrid uneditable
              Fredsells
              would you mind posting the code for myCheckbox (or perhaps you can just help me with thisproblem) I've got a datagrid with a checkbox editor. I cannot get the click="myFunction()" to see myFunction. There must be some magic "scoping" I don't know, but I'm stuck.
              • 4. Re: can't make checkbox  in datagrid uneditable
                ntsiii Level 3
                Or try setting rendererIsEditor="false".
                Tracy
                • 5. Re: can't make checkbox  in datagrid uneditable
                  travisdh1
                  quote:

                  Originally posted by: Fredsells
                  would you mind posting the code for myCheckbox (or perhaps you can just help me with thisproblem) I've got a datagrid with a checkbox editor. I cannot get the click="myFunction()" to see myFunction. There must be some magic "scoping" I don't know, but I'm stuck.


                  You're correct about you're problem being the scope. Just put "outerDocument." in you're click handler so it looks like click="outerDocument.myFunction()" I know this works, but can't explain exactly why off the top of my head. I do know that itemRenderers do a lot of stuff for you in the background, one of the effects is that they can't access things outside of the instance unless you use the outerDocument keyword.