8 Replies Latest reply on Apr 3, 2008 12:57 PM by GeorgeWS

    Selecting checkbox as selected within a datagrid

    Novian
      Hi,

      I think I have a targeting problem. My app places a number of checkboxes within a datagrid using an itemRenderer. The user can select a number of checkboxes and the results are stored in a db. I then return the results from the db as an ArrayCollection. I'm trying to loop through the ArrayCollection and select the appropriate checkboxes. The thing is, I can't quite figure out how to mark the checkboxes as selected based on these results. Any thoughts would be greatly appreciated.

      Thanks.

      Novian
        • 1. Re: Selecting checkbox as selected within a datagrid
          GeorgeWS Level 1
          I am trying to do the exact same thing can you post your code on this topic.
          • 2. Re: Selecting checkbox as selected within a datagrid
            BLXWebMaster Level 1
            I have struggled with the same issue several times, I finally decided on a solution that is very flexible and easily allows for Checking All Check Boxes, None, Etc.

            I simply add a column to my array and use that to store a boolean. Then setup binding on the chekbox selected attribute.

            So...

            <mx:CheckBox selected="{data.strChecked == '1'}"/>

            Now in your array collection or in your actually query add a column called strChecked. You can easily add to your SQL statement "0 As strChecked".

            So you know have a column strChecked called in your array with a vlue of "0".

            Then just call a function like this...

            private function checkAllOther():void {
            var length : int = dg.dataProvider.length;
            for( var i : int = 0; i < length; i++ )
            {
            var item : Object = ar.getItemAt( i );
            item["strChecked"] = '1';
            }

            ar.refresh();
            }

            This will select all, but you can easily just change the
            var length : int = dg.dataProvider.length; to var length : int = "Value Returned From DB";

            Make Sense?





            • 3. Re: Selecting checkbox as selected within a datagrid
              GeorgeWS Level 1
              Thanks,
              I might be able to use this later. But im really having trouble just getting data from my datagrid and a form item (like a textfield) to add into a db table. I dont want to use XML (most samples are XML).

              What i need is:
              RemoteObject to ArrayCollection (this works)
              The ArrayCollection fills the datagrid (this works)
              Then a few items get checked using the checkbox column (this does not work)
              A few form fields get filled in or selected (this works)
              Then SEND and the records go to a DB. All I can get are the form fields to update a table not the datagrid. (partial working)
              this is what I have:

              http://www.youngsmarket.com/youngsmarket/programs/national/nataccpro/bin/srcview/index.htm l?SupplierID=30

              Thanks for looking (I know I went off topic but your the king and have helped me so many times)

              George
              • 4. Re: Selecting checkbox as selected within a datagrid
                ntsiii Level 3
                George, this: "Then a few items get checked using the checkbox column (this does not work)" is the key.

                You must do as I and BLXWebMaster advise: "add a column to my array and use that to store a boolean", Whatever your dataProvider is, or how you get it, you MUST have the itemRenderer update the dataProvider item, and the itemRenderer must set its value form the dataProvider item.

                Until you can do this you will be unsuccessful.

                Tracy
                • 5. Re: Selecting checkbox as selected within a datagrid
                  GeorgeWS Level 1
                  I see what you are saying about the check box (but still stumped). I am sure I need to see the data actually update. If I could get the grid data and the form fields to update/add to a table that would be great (Im not smart enough to do it without a sample). Temporaraly forget about the checkbox; just data into grid and form fields filled out. Then in the database table each grid record will have the grid record and the form fields. Then Im sure I could get the checkbox part to work. I should have no problem with the CFC. But I dont know how to send the modified datagrid array back to the CFC with the form fields. What does the function look like; what are the commands I can use? datagrid row + form fields = table record HOW?

                  Thanks
                  George
                  • 6. Re: Selecting checkbox as selected within a datagrid
                    GeorgeWS Level 1
                    Im still confused...
                    I see multiple examples of the checkbox in the datagrid, most work fine in the sample but they just dont relate to what I am doing (I am not interested in checking all just a empty checkbox to be checked if you want that record to be added to the DB). I have only 2 things to finish my app. Checkbox in datagrid and send those checked records along with some form fields. Does anyone know how to do this? If so how? Please dont show me an XML sample I use the RemoteObject and ArrayCollection.

                    Thanks
                    George
                    • 7. Re: Selecting checkbox as selected within a datagrid
                      GeorgeWS Level 1
                      I have tried multiple samples from the forums and the liveDocs and a few from some blogs. NONE work properly. How hard can it be to add a check box into datagrid? Im using CF7 and Flex 2.01
                      • 8. Re: Selecting checkbox as selected within a datagrid
                        GeorgeWS Level 1
                        Thanks you very much; some how I undersood today. One more question. How do you uncheck them?

                        This is what I ended up with that checks All boxes displayed in the datagrid:

                        private function selectAll():void {
                        var length : int = myDataGrid.dataProvider.length;
                        for( var i : int = 0; i < length; i++ )
                        {
                        var item : Object = myAccounts.getItemAt( i );
                        item["Include"] = '1';
                        }
                        myAccounts.refresh();
                        }

                        Thanks Alot

                        George