Combo Box



 Combo box is a graphic object that displaying items when entering several items, and pressing the extension button of objects.



                               


                               


 Combo box is used to display or select one among various items.


 Combo box provides the following functions and events.




Methods




Return Type

Method

Description


addItem( text )

Add an item to the combo box.


addItems( texts )

Add items to the combo box.


addItemWithValue( text, value )

Add an item to the combo box and set the data.


clear()

Clear all items of the combo box.


connect( eventName, func )

Register an event handler to find the select is changed.

int

count()

Obtain the number of combo box items.

int

currentIndex()

Obtain the number of the currently selected item in the combo box.

str

currentText()

Obtain the String of the currently selected item in the combo box.


insertItem( index, text )

Insert an item to the combo box.

variant

itemData( index )

Read the data of that property.

str

itemText( index )

Obtain the String of combo box properties.


removeItem( index )

Remove the property of combo boxes.

variant

selectedItemData()

Read the data of the selected property.


setCurrentIndex( index )

Set displaying properties of the combo box.


setCurrentIndexByValue( value )

Find and select a property with that value.


setCurrentText( text )

Find and select a property with that String.


setItemText( index, text )

Modify the String of properties.



  addItem( text:String )

 

  addItem enters the String property to the combo box.


        ㆍ Enter String to text.

        ㆍ It enters in ascending order.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       obj.addItem('12345');  << Enter 12345 as 0th item.

       obj.addItem('67890');  << Enter 67890 as 1st item.




                               



  addItems( texts:String list )

 

  addItems enters a list of String to the combo box.


        ㆍ Enter a list of String to texts.

        ㆍ It enters in ascending order.



  Example)

   


       obj = canvas.getObject('CheckBox');  << Obtain the checkbox object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.




                               



  insertItem( index:Enter point(number), text:String )

 

  insertItem inserts the String at an index point of the combo box.


        ㆍ Existing items position in incremented by 1.

        ㆍ Enter String to text.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       obj.insertItem( 2, ‘0000’);

       << Insert to the second item('aaaa'). Index increments by 1.




                               



  setItemText( index:Enter point(Number), text:String )

 

  setItemText modifies the String at index point to the text.


        ㆍ index starts from 0 on the top.

        ㆍ Enter String to text. Enter String to text.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       obj.setItemText( 2, ‘0000’);   << Modify to 0000




                               



  removeItem( index:Enter point(Number) )

 

  removeItem removes after index in the combo box.


        ㆍ After removing, every index is decreased by 1.


  Example)Rmove the second item('aaaa').

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       obj.removeItem( 2 );   << Remove the second item('aaaa').




                               



  clear()

 

  clear removes all items of the combo box.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       obj.clear();   << Remove all items.




                               



  int count()

 

  count returns the number of properties.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       value = obj.count();   << Enter the number of properties to value.

       app.messageBox( value );  << Print value.




                               



  str itemText( index:Item position )

 

  itemText obtains the String of the property positioning at index.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       value = obj.itemText(0);   << Enter String to the oth index item to value.

       app.messageBox( value );  << Print value.




                               



  int currentIndex()

 

  currentIndex obtains the index number of the selected item in the combo box.


        ㆍ Combo box displays the item user selected.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       value = obj.currentIndex();   << Enter the current index to value.

       app.messageBox( value );  << Print value.




                               



  str currentText()

 

  currentText obtains the String of the selected item in the combo box.


        ㆍ Combo box displays the item user selected.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       value = obj.currentText();   << Enter the current text to value.

       app.messageBox( value );  << Print value.




                               



  setCurrentIndex( index:Item position )

 

  setCurrentIndex displays the item displayed on the screen as an index item.


        ㆍ Combo box displays the item of index 0 if it has no setCurrentIndex setting.

        ㆍ If the user selects by clicking the combo box, the item is displayed.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

       a = ['1111', '2222', 'aaaa', 'bbbb'];  << Enter items to a as a list.

       obj.addItems( a );  << Enter list a.

       obj.setCurrentIndex(1);   << Show the first item.




                               


  addItemWithValue( text:Item to add, value:Data to set )

 

  Add an item to the combo box and set its data.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

     

       obj.addItemWithValue('Apple' , 32 );  << Add an Apple to the combo box, and set 32 to Apple.





  variant selectedItemData()

 

  Read the data of the currently selected item. Do not read the value if the data does not set.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box.

     

       value = obj.selectedItemData();  





  variant itemData( index:Item number )

 

  Read the data of the currently selected item. Do not read the value if the data is not set.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

     

       value = obj.itemData(3);  # Obtain the third item.





  setCurrentIndexByValue( value:Data value )

 

  Find and select the property with that value.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

     

       value = obj.setCurrentIndexByValue(32);  # Select the item which had 32.





  setCurrentText( text )

 

  Find and select the property with that String.



  Example)

   


       obj = canvas.getObject('ComboBox');  << Obtain the combo box object.

     

       value = obj.setCurrentText('Apple');  # Select Apple.





  connect( eventName: Event handler name , func: Receiving function )

 

  Receive events of the combo box. When changing the currently selected item, it occurs 'item changing event', and register the function to find that the item is changed in the combo box.



  Example)

   


       # Define the receiving function.

       def indexChanged(index) :

              print 'Change items' , index


       obj = canvas.getObject('ComboBox') # Obtain the combo box object.

       obj.connect('currentIndexChanged(int)', indexChanged)  # Register the receiving function.