6 Replies Latest reply on May 21, 2008 9:45 AM by May 2008

    Checkbox problem

    May 2008 Level 1
      Hi everyone,

      How to loop through the checkbox which is inside a datagrid?

      Thanks,
      May
        • 1. Re: Checkbox problem
          Izzy1138
          What are you looking to do? Just a though. I use a class for the lineItem ( that I write with an member variable for each column ) and a list of those for the dataprovider. That way I can dig through the data without dealing with the datagrid at all. It also make moving the data around easier. Instead of reading out each line into something else, you just send the list of lineItems.
          • 2. Re: Checkbox problem
            May 2008 Level 1
            Hi,

            Thanks for your reply. What I want to do is shown below. And the datagrid is shown below:

            |---------|----------------|----------------|
            | id | Checkbox | TextInput |
            |---------|----------------|----------------|
            | 1 | false | |
            | 2 | true | Create |
            | 3 | true | Update |
            |---------|---------------|----------------|

            What I want to do is loop through the checkbox which is inside a datagrid. If it is true, then get the id value and TextInput value out from the datagrid. And then update the database.

            Thanks,
            May
            • 3. Re: Checkbox problem
              David_M..
              Hi,

              One solution to your problem could be:
              - Create a class "myItem" representing one line of information with 3 attributes: id (int), checked(boolean) and textValue(String)
              - Create an arrayCollection which will be the dataprovider of your datagrid. This arrayCollection will contains object of type "myItem".
              - In the item renderer of the column with the checkbox, on the CheckBox object add a change listener like this id="chkbox" change="(this.data as myItem).checked = chkbox.selected"

              When you want to check if there is something checked, you don't use the datagrid anymore but simply go through the arrayCollection you gave as a dataprovider.

              Hope it's clear.

              David
              • 4. Re: Checkbox problem
                MayLam18
                quote:

                Originally posted by: David M..
                Hi,

                One solution to your problem could be:
                - Create a class "myItem" representing one line of information with 3 attributes: id (int), checked(boolean) and textValue(String)
                - Create an arrayCollection which will be the dataprovider of your datagrid. This arrayCollection will contains object of type "myItem".
                - In the item renderer of the column with the checkbox, on the CheckBox object add a change listener like this id="chkbox" change="(this.data as myItem).checked = chkbox.selected"

                When you want to check if there is something checked, you don't use the datagrid anymore but simply go through the arrayCollection you gave as a dataprovider.

                Hope it's clear.

                David


                Hi David,

                Thanks for your help! I am new to Flex. If possible, please give me sample code. Thanks again!

                May
                • 5. Re: Checkbox problem
                  David_M.. Level 1
                  Hi,

                  I did the following quick and didn't test it but I guess it should work.

                  Good luck,
                  David
                  • 6. Re: Checkbox problem
                    May 2008 Level 1
                    That's great. Thanks a lot David. I will try your code later.

                    May