ComboBox with variable dropdown width.


hi, have 1 custom combo box, useful to show tool tip on items & has variable drop-down width to show items properly.

hope if 1 needed.

 

<?xml version="1.0" encoding="utf-8"?>
<mx:combobox xmlns:mx="http://www.adobe.com/2006/mxml" creationcomplete="init();" updatecomplete="adjustcombodropdownwidth();"
    buttonmode="true">
   
    <mx:script>
    <![cdata[
        import mx.controls.list;
         private var _selectedvalue:string;
       
         private var _selectedlable:string;
         
         private var bselectedvalueset:boolean = false;
         private var bdataproviderset:boolean = false;
        
         [bindable]
            private var mydropdownfactory:classfactory;   
         // override committ, may called repeatedly
         override protected function commitproperties():void
         {
            // invoke combobox version
            super.commitproperties();


            // if value set , have dataprovider
            if (bselectedvalueset && bdataproviderset)
            {
               // set flag false code won't called until selectedvalue set again
               bselectedvalueset=false;
               // loop through dataprovider
               (var i:int=0;i<this.dataprovider.length;i++)
               {
                  // item's data
                  var item:string = this.dataprovider[i].data;
                      
                  // check if selectedvalue
                  if(item == _selectedvalue)
                  {
                     // yes, set selectedindex
                     this.selectedindex = i;
                     break;
                  }
               }
            }
         }


         // trap dataprovider being set
         override public function set dataprovider(o:object):void
         {
            // invoke combobox version
            super.dataprovider = o;


            // may called before dataprovider set, make sure not null , has entries
            if (o!=null && o.length)
            {
               // got it, set flag
               bdataproviderset = true;
            }
         }


         // set selectedvalue
         public function set selectedvalue(s:string):void
         {
            // set flag
            bselectedvalueset = true;
            // save value
            _selectedvalue = s;
            // invalidate force commit
            invalidateproperties();
         }
        
         /**************************************************************************************** **
       
          * @description : show tool-tip on line items objects of combobox.
          ***************************************************************************************** /
          public function init():void
          {
                mydropdownfactory         = new classfactory(list);
                mydropdownfactory.properties = {showdatatips:true, datatipfunction:mydatatipfunction}
                this.dropdownfactory    = mydropdownfactory;
          }         
         
             private function mydatatipfunction(value:object):string
          {
                return (value.label);
          }


         /**************************************************************************************** **
        
          * @method name : adjustcombodropdownwidth()
          * @i/p params  : combobox
          * @return         : number
          * @description : computes dropdown width according dataprovider provided it.
          ***************************************************************************************** /
          private function adjustcombodropdownwidth():void
          {
                  this.dropdownwidth    = calculatecustompreferredsizefromdata();                  
          }                      
        
         /**************************************************************************************** **
      
          * @method name : calculatecustompreferredsizefromdata()
          * @i/p params  : -
          * @return            : number
          * @description : computes dropdown width according dataprovider provided it.
          ***************************************************************************************** /
          public function calculatecustompreferredsizefromdata():number
          {
                var dropdownwidth:number    = this.calculatepreferredsizefromdata(this.dataprovider.length).width+14;
                if(dropdownwidth > this.width)
                {
                    return dropdownwidth;
                }
                else
                {
                    return this.width;
                }
          }
      ]]>
   </mx:script>
</mx:combobox>

 

thanks.

hey prashant... chaan...avadlay....that gud..helped me lot



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Installation database is corrupt

Error compiling for board Arduino/Genuino Uno.

Nogen der kender et simpelt hvidt template med topmenu kun - Joomla! Forum - community, help and support