The MaxGUI Beginner Tutorial Series - Tutorial 10:  ComboBoxes
(c) Assari Dec 26 2005

In this tutorial we are going to look at ComboBoxes, a very similar gadget to Listboxes, which we had covered rather extensively in the three previous tutorials.

Lets take a look at a simple ComboBox:-

    SuperStrict

Local MyWindow:TGadget=CreateWindow("ComboBox Example", 200,200,320,240)
Local ComboBox:TGadget=CreateComboBox(10,10,200,100,MyWindow)

AddGadgetItem  ComboBox,"First Item"
AddGadgetItem  ComboBox,"Second Item"

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
   End Select
Forever


ComboBoxes requires the user to click on the downarrow button to activate the drop down.
 This is of course cheaper on screen real estate.

   


We can also set a default item as follows:-
    SuperStrict

Local MyWindow:TGadget=CreateWindow("ComboBox Example", 200,200,320,240)
Local ComboBox:TGadget=CreateComboBox(10,10,200,100,MyWindow)

AddGadgetItem  ComboBox,"First Item"
AddGadgetItem  ComboBox,"Second Item"
SelectGadgetItem  ComboBox,1

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
   End Select
Forever


As we can see from the picture below, the Second Item text appears in the ComboBox ready to be selected.

   


Just like ListBoxes, we can use the SelectedGadgetItem to retrieve the index and GadgetItemText to retrieve the element itself. Let us see an example of these functions in action

    SuperStrict

Local MyWindow:TGadget=CreateWindow("ComboBox Example", 200,200,320,240)
Local ComboBox:TGadget=CreateComboBox(10,10,200,100,MyWindow)

For Local i:Int=1000 To 1050
  AddGadgetItem ComboBox,i
Next
Local s:String

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
  Case EVENT_GADGETACTION
     s=GadgetItemText(ComboBox,SelectedGadgetItem(ComboBox))
     SetStatusText MyWindow,
"index="SelectedGadgetItem(ComboBox) + ":item=" + s
   End Select
Forever

As we can see below, the selected item is displayed by the above SetStatusText function on the status bar. Note that the above program is very similar to an earlier example in Tutorial 8 using listboxes instead of comboboxes. A lot of the functions which apply to Listboxes also apply to Comboboxes as well.

   



Summary

This has been a short tutorial, simply because we have covered all the functions that can be used to manipulate a combobox in the previous listbox tutorials.

To recap what we have learnt so far
So thats ends our tutorial for now. Back to Tutorial Index.