3 Replies Latest reply on Sep 19, 2011 10:51 AM by clb2196@gmail.com

    How to disallow duplicates in datagrid drag & drop

    clb2196@gmail.com

      Hi guys, I'm a total n00b to Flex, and I'm hoping you can help me out. I have 2 very basic data grid. The first one is populated via XML, and you can drag and drop items onto the second grid. What I'm wondering is how do you do data validation before enabling the drag & drop? I want to avoid duplicates or conflicts (where one of the column values matches what is currently there). If they try to drag & drop a duplicate, I want to deny it, and pop up a warning box. A lot of the examples I've found have to do with filtering arrays which I don't think helps since I'm populating directly from the XML, or it does the validation after populating the grid and I need it done before. Thanks.

        • 1. Re: How to disallow duplicates in datagrid drag & drop
          LoganSix Level 1

          When you do the DragDrop, you can add a function to verify if the item already exists in the dataprovider.

           

          On the destination grid, you add the dragDrop function.

          <mx:DataGrid id="destgrid"                dragDrop="dragDropHandler(event);">

           

          In the dragDropHandler function you can look through the destination dataprovider to see if the source item has a matching item.  You can use indexOf to search the array for a matching item.

           

          Live Doc DragDrop information

          http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_4.html

           

          Live Docs Array information

          http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html

          • 2. Re: How to disallow duplicates in datagrid drag & drop
            clb2196@gmail.com Level 1

            Whew, ok, I think I'm getting the hang of this. So I'm calling my dragDrop handler method, and it's working. However, checking if the object exists isn;t working. Can I convert the data provider directly to an array? This is what Im doing- but I'm never getting inside that if:

             

            private function dragDrop(evt:DragEvent):void {

                                                    var chosen:Object = courseGrid.selectedItems;

                                                    for each (var chosenObj:Object in chosen){

                                                              if (summaryGrid.dataProvider.contains(chosenObj)){

                                                                        DragManager.acceptDragDrop(evt.dragInitiator);

                                                                        Alert.show("Duplicate");

                                                              }

                                                                        else{

                                                                                  DragManager.acceptDragDrop(summaryGrid);

                                                                        }

                                                                        }

                                          }

            • 3. Re: How to disallow duplicates in datagrid drag & drop
              clb2196@gmail.com Level 1

              Ok, ended up convrting to an array and looping through.

               

              The underlying problem seems to be I can't actually get it to reject the drag and drop. I can get it to show the "Duplicate" warning, but no matter what I do, even if I remove the acceptdragdrop call completely within the if, it still lets me drop the row. Help?