5 Replies Latest reply on Jan 11, 2010 6:55 AM by PeakDigital

    Begin Tree edit on double-click instead of click?

    PeakDigital Level 1

      My project uses a Tree control that allows the node titles to be edited. However, we have found that it creates a usability issue for the Tree to enter edit mode upon a single-click event.

       

      What is the most reliable method to defer the edit mode until the user double-clicks on the node?  Am I on the right track thinking to set the tree's .editable=false, then attach a listener on the double-click event that would change it to .editable=true and manually send the ITEM_EDIT_BEGINNING event?

       

      Thanks.

      Paul

        • 1. Re: Begin Tree edit on double-click instead of click?
          archemedia Level 4

          could you post a little example which makes it possible to see the problem?

           

          d

          • 2. Re: Begin Tree edit on double-click instead of click?
            archemedia Level 4

            this might do the trick:

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:components="components.*">

             

                <mx:Script>
                    <![CDATA[
                        import mx.events.ListEvent;
                       
                        private function handleDoubleClick(evt:Event):void
                        {
                            var le:ListEvent = new ListEvent("itemEditBegin");
                            le.reason = "dClick";
                            le.rowIndex = evt.currentTarget.selectedIndex;
                            evt.currentTarget.dispatchEvent(le);
                        }
                       
                        private function handleItemEditBegin(evt:ListEvent):void
                        {
                            if (evt.reason != "dClick")
                                evt.preventDefault();
                        }
                    ]]>
                </mx:Script>
               
                <mx:Tree id="myTree"
                    itemEditBegin="handleItemEditBegin(event)"
                    editable="true"
                    doubleClickEnabled="true"
                    doubleClick="handleDoubleClick(event)">
                    <mx:Array>
                        <mx:String>item one</mx:String>
                        <mx:String>item two</mx:String>
                        <mx:String>item three</mx:String>
                    </mx:Array>
                </mx:Tree>
            </mx:Application>

            1 person found this helpful
            • 3. Re: Begin Tree edit on double-click instead of click?
              PeakDigital Level 1

              Thank you for your reply and sample code. It partly works. It no longer enters edit mode upon a single click.

               

              However, I keep getting error 1009 on line 2603 of List.as, inside the function itemEditorItemEditBeginHandler(event:ListEvent). It is expecting a value  for .rowIndex in an object called _editedItemPosition.

               

              I have even tried creating and setting the object prior to dispatching the event, but it remains null. Either my code isn't being received or something resets it to null after it runs. I used this code in the beginning of the handleDoubleClick function:

               

              var objEIP:Object=new Object;
              objEIP.rowIndex=event.currentTarget.selectedIndex;
              objEIP.columnIndex=0;
              treePrimaryListManager.editedItemPosition=objEIP;
              

               

              "treePrimaryListManager" is the Tree component I am working with in this code.

               

              Paul

              • 4. Re: Begin Tree edit on double-click instead of click?
                archemedia Level 4

                You should debug your second line of code and see what currentTarget is. In my example, evt is a regular MouseEvent.

                Also, in your code, you refer explicitly to your tree component (treePrimaryListManager). Doing this makes the code not suitable for re-use on other list components you may use in your app.

                 

                Try to isolate the problem and post the entire code so I can look into it.

                 

                d

                • 5. Re: Begin Tree edit on double-click instead of click?
                  PeakDigital Level 1

                  Thank you for your further assistance and input.

                   

                  currentTarget is my Tree.

                   

                  I am not concerned about reusability of this single line of code.

                   

                  The problem is isolated to immediately after the dispatchEvent(le) is executed. I cannot post the entire application code.

                   

                  After my last post I found an alternative solution to my problem.