2 Replies Latest reply on Nov 16, 2007 12:03 PM by Chuck_Reed

    CheckBoxes in DataGrid column

      I am loading a data grid with a few columns of text data and one column of checkboxes. The datagrid is defined like this:

      <mx:DataGrid id="dgUpdateDetail" x="450" y="33" width="456" height="226">
      <mx:DataGridColumn headerText="Name" dataField="name" width="100"/>
      <mx:DataGridColumn headerText="My Value" dataField="localValue" width="200"/>
      <mx:DataGridColumn headerText="New Value" dataField="newValue" width="200"/>
      <mx:DataGridColumn id="colSelection" headerText="Selected" dataField="selected"
      editorDataField="selected" editable="true" rendererIsEditor="true">
      <mx:CheckBox click="data.selected =! data.selected" selected="{data.selected}"/>

      Later, I bind an XML result object as the grid's data provider, here is an example of what it looks like and a sample XML result:

      public var updateDetails:XML;
      updateDetails = new XML("<data><name>Field1</name><localValue>1</localValue><newValue>2</newValue><selected>f alse</selected></data>");
      pnlUpdate.dgUpdateDetail.dataProvider = updateDetails;

      Now, the textual information all loads properly in the first 3 columns. The checkbox *always* loads checked, and when I click on it, the value remains checked. I've tried small variations to this, but all seem to fail for me. Anyone have a clue what I may be missing to properly bind my XML source to these check boxes?
        • 1. Re: CheckBoxes in DataGrid column
          ntsiii Level 3
          That mostly looks ok. As you are doing, you must update the dataProvider on click, and set the checkbox state from the item data.

          The forum cut off your xml, but that is one possible area of problem. to debug, change the checkbox to a label, and just display the data.selected value. Make sure it is getting referenced correctly.

          Also, this:
          data.selected =! data.selected
          looks logical, and is probably fine, but I would do:
          <mx:CheckBox id="cbx" click="data.selected = cbx.selected"

          • 2. Re: CheckBoxes in DataGrid column
            Chuck_Reed Level 1
            Thanks for the reply, Tracy.

            Since I'm using XML instead of an actual boolean, I realized my checkbox needed to be created like so:
            <mx:CheckBox click="data.selected = selected.toString()" selected="{(data.selected == 'true')}" />

            It seems to be working as I would expect now.