3 Replies Latest reply on Mar 25, 2010 8:29 PM by Klaus3891

    Able to drag drop items of combobox but want to disable 1st item

    Prashant Waykar Level 1

      Hello Sir,

       

      I am able to drag drop elements of the combobox.

      Here is my code...

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*" xmlns:utils="adobe.utils.*" xmlns:controls="qs.controls.*" initialize="init()">

      <mx:Script>

      <![CDATA[

      import mx.events.DragEvent;

      import mx.events.ListEvent;

      import mx.controls.dataGridClasses.DataGridColumn;

      import mx.controls.ComboBox;

      import mx.controls.Alert;

      [Bindable]

      public var str:String = "";

      public var comboLength:int;

      public function init():void

      {

      var xml:XML = <test>

      <col>

      <col1>one</col1>

      </col>

      <col>

      <col1>two</col1>

      </col>

      <col>

      <col1>three</col1>

      </col>

      <col>

      <col1>four</col1>

      </col>

      <col>

      <col1>five</col1>

      </col>

      <col>

      <col1>six</col1>

      </col>

      <col>

      <col1>seven</col1>

      </col>

       

        </test>;

       

        cb1.dataProvider = xml;

        comboLength = xml.col.length();

        cb1.rowCount = comboLength;

        str = (xml.col[0].col1.toString());

        cb1.prompt = str;

       

      }  

       

      public function closeHandler(event:Event):void

      {

      if(MouseEvent.DOUBLE_CLICK)

      {

      // Alert.show("Click Event");

      }

      }

       

      public function changeHandler(event:ListEvent):void

      {

      // Alert.show("Single Click Event");

      }

       

      public function doubleClickEvent(event:MouseEvent):void

      {

      Alert.show(event.currentTarget.toString());

      Alert.show(event.target.toString(),"Double Click");

      }

       

      public function dragEnterFunction(event:DragEvent):void

      {

      Alert.show(event.target.parent.toString());

      }

       

       

      ]]>

      </mx:Script>

       

      <mx:ComboBox id="cb1" prompt="prashant" doubleClickEnabled="true" doubleClick="doubleClickEvent(event)"

      close="closeHandler(event)" dragEnter="dragEnterFunction(event)" >

      <mx:itemRenderer>

      <mx:Component>

      <mx:DataGrid itemClick="outerDocument.cb1.text = this.selectedItem.col1.toString();itemSelected(event)"

      dragEnabled="true" dropEnabled="true" dragDrop="draDropHandler(event)" dragMoveEnabled="true" headerHeight="0" showHeaders="false"

      creationComplete="init()" click="clickable()"

      itemDoubleClick="doubleClickEvent(event)">

      <mx:columns>

      <mx:DataGridColumn dataField="col1" headerText="" id="da" disabledColor="white"  />

      </mx:columns>

      <mx:Script>

      <![CDATA[

      import mx.controls.DataGrid;

      import mx.events.DropdownEvent;

      import mx.events.ListEvent;

      import mx.events.DragEvent;

      import mx.controls.Label;

      import mx.controls.Alert;

      public function clickable():void

      {

      //Alert.show("clickable");

      }

       

      public function itemSelected(event:ListEvent):void

      {

      Alert.show(event.itemRenderer.data.col1,"Single Click");

      }

       

           public function draDropHandler(event:Event):void

      {

      Alert.show(event.target.parent.toString());

      }

       

      public function dragEnterFunction(event:DragEvent):void

      {

      Alert.show(event.target.parent);

      }

       

      override public function set data( value:Object ) : void

      {

      this.dataProvider = value.col;

      //outerDocument.cb1.text = this.selectedItem.col1.toString()

      }

       

      //myList.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick,

      public function doubleClickEvent(event:ListEvent):void

      {

      Alert.show(event.itemRenderer.data.col1,"Double Click");

      }

       

      ]]>

      </mx:Script>

      </mx:DataGrid>

      </mx:Component>

      </mx:itemRenderer>

      </mx:ComboBox>

       

      </mx:Application>

      But now i want to disable drag drop of the 1st item and the last item.
      And also add double click of each item.
      Can someone please help me out.
      Awaiting your reply.
      Thanks in advance.

        • 1. Re: Able to drag drop items of combobox but want to disable 1st item
          Jason Szeto Level 3

          Prashant,

           

          I'm going to assume you mean that you don't want to allow the 1st and last items of the ComboBox to be draggable. If this is the case, then I'd subclass List and override the dragStartHandler function. In your override, check to see if the target is the first or last row (you might be able to use ListBase.calculateDropIndex to figure out your row index). If it is not, then call super.dragStartHandler.

           

          As for supporting double click of each ComboBox item, that is going to be more tricky. ComboBox has logic that will close the dropDown on an item click or a "change" event from the dropDown (as long as you aren't using the navigation keys such as UP, DOWN). You'll need to disable this behavior. Unfortunately the functions dropdown_changeHandler and dropdown_itemClickHandler are private. So you'll need to copy the ComboBox source code and modify that code.

           

          Jason

          1 person found this helpful
          • 2. Re: Able to drag drop items of combobox but want to disable 1st item
            Prashant Waykar Level 1

            Hello Sir,

            Thanks a lot for your reply.

            I have implemented some thing can you please help me out with this?

            In this can you help me out with the double click event????

             

             

             

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"

            xmlns:local="" xmlns:utils="adobe.utils." xmlns:controls="qs.controls.*"

            initialize="init()">

            <mx:Script>

            <![CDATA[

            import mx.events.DragEvent;

            import mx.events.ListEvent;

            import mx.controls.dataGridClasses.DataGridColumn;

            import mx.controls.ComboBox;

            import mx.controls.Alert;

            import mx.controls.listClasses.ListBase;

            import mx.core.UIComponent;

            public var str:String = "";

            public var comboLength:int;

            public function init():void

            {

            var xml:XML =

            </mx:Application

            • 3. Re: Able to drag drop items of combobox but want to disable 1st item
              Klaus3891

              Here is a great combobox Component that allows you to enable/disable any item in the combobox. it works exactly like a combobox in any enabled item and it does nothing in the disabled ones. I havent tried to drag from it but it should work just fine since for every other case it is a combobox

               

              http://wmcai.blog.163.com/blog/static/4802420088945053961/