3 Replies Latest reply on Apr 3, 2009 7:10 AM by Newsgroup_User

    DataGrid with RadioButtons

    BobFromTheYear5K
      I've finally become frustrated enough with this to go through the effort of posting on the forum. :-)

      I have a DataGrid being populated by external XML. The first col in the grid contains RadioButtons. I want to select / deselect a radio button on a row click. If the user happens to click directly on one of the RadioButtons, no problem. But I can't seem to come up with any way to change the selection state when the user clicks on some other col in the row.

      In Java I used to be able to grab the contents of a cell using [row, col] coordinates. Is there some analog in Flex? Or some other way I can get at those RadioButtons?

      I've spent half my day trying to accomplish something that I thought should be relatively straight-forward.

      Code is below, if it helps. Though there's no much to it. Note that there is no 'dataField' associated with the RadioButtons, because there is no corresponding data field in the XML. They exist strictly as part of the design.
        • 1. Re: DataGrid with RadioButtons
          Peter Hahmann
          Do the following:

          Although when looking at the code it seems that there will be only one ItemRenderer, when data populates your grid, there is one different renderer for each row. Add a data binding to you radio button "selected" property (Boolean(int(data.isSelected))), so your RadioButton will be able to listen and "react" to changes. Now you'll have to create a logic for the radio button, create a <mx:Scrip> right above your RadioButton tag and when create a method where you define that data.isSelected = int(e.target.selected);. Make the same procedure when clicking a row the grid.

          If you can't work it out, let me know. I'll make an example.

          Regards,
          Peter
          • 2. Re: DataGrid with RadioButtons
            BobFromTheYear5K Level 1
            So close....

            It almost works. If I click on the 1st row, then click on a row farther down the grid, then scroll the grid, the radio button selection reverts back to the first row.

            Can you do me a favor and explain the logic behind your suggestion? I think you may be trying to take advantage of some aspect of ActionScript that I don't quite understand yet.

            Like where does "data.isSelected" come from and what information is being stored in "target.selected"?

            Is there any reason why I could not do this inside the main <script> tag and then reference it using "outerDocument"?

            Here's how I'm implementing this so far:



            • 3. Re: DataGrid with RadioButtons
              Level 7

              "BobFromTheYear5K" <webforumsuser@macromedia.com> wrote in message
              news:gr34i9$87h$1@forums.macromedia.com...
              > So close....
              >
              > It almost works. If I click on the 1st row, then click on a row farther
              > down
              > the grid, then scroll the grid, the radio button selection reverts back to
              > the
              > first row.
              >
              > Can you do me a favor and explain the logic behind your suggestion? I
              > think
              > you may be trying to take advantage of some aspect of ActionScript that I
              > don't
              > quite understand yet.
              >
              > Like where does "data.isSelected" come from and what information is being
              > stored in "target.selected"?
              >
              > Is there any reason why I could not do this inside the main <script> tag
              > and
              > then reference it using "outerDocument"?

              http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
              Check out Q2 and Q3

              HTH;

              Amy