COMBOBOX

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

A COMBOBOX is a control on a GUI window that consists of a drop-down list and a textbox field. The selection chosen from the list is displayed in the textbox.
Comboboxes are similar to Listboxes, but use less space.

Syntax

  1. COMBOBOX #handle.ext, array$(), eventHandler, x, y, wide, high

Syntax notes

  • #handle.ext Must be a unique .extension so commands can be written to control after window is opened.
  • array$() The string array contains the items that are displayed in the combobox drop-down list after the window is opened.
  • eventHandler The branch label or subroutine where program flow continues after an item is selected from the combobox drop-down list.
  • x, y The x and y coordinates which position the combobox from the upper left corner of the window.
  • wide and high The width of the control. Height is the length of the drop-down list (in pixels) when the list is open - this parameter is ignored from Win XP up. (The height of the closed combobox, the textbox field, is dependant on the font used.)

Combobox Features

  • Selecting an Item. The user can select from the drop-down list by clicking an item. The user can also select by typing into the textbox field. The listed match will become the selection.
  • Loading the Array. To display items in the combobox, the array must be loaded before the window is opened. The array may be loaded by coding the literal strings in the program listing, by using DATA and READ statements, or by inputting data from a disk file.
  • Changing the Contents of the List. To add or remove an item from the combobox, you must add it or remove it to/from the array. Before the change will show up in the combobox drop-down list, a RELOAD command must be issued. Issuing a RELOAD at any time updates the contents of the combobox.
  • Width and Height of Drop-down List. When open, the combobox height automatically adjusts to display all the items ("high" parameter is ignored from Win XP and up). Then making long list, vertical scroll bar appears. The width does not increase if an item is longer than what is specified in wide parameter. Horisontal scroll bars are not provided in comboboxes.

Combobox Commands

The following commands (Methods) can be used with combobox controls. See the individual pages for discussion.

Combobox Variables

The following variables can be used with combobox controls. See the individual pages for discussion.

Example

From the JustBASIC Help file

A combobox demo with branch label event handler.

nomainwin
a$(1) = "one"
a$(2) = "two"
a$(3) = "three"
a$(4) = "four"

combobox #win.combo, a$(),[doCombo],10,10,120,200
open "Combobox Demo" for window as #win
#win "trapclose [Quit]"
#win.combo "selectindex 1"

wait

[Quit] close #win:end

[doCombo]
#win.combo "selection? sel$"
notice "You chose ";sel$
wait

A combobox demo with subroutine event handler.

nomainwin
a$(1) = "one"
a$(2) = "two"
a$(3) = "three"
a$(4) = "four"

combobox #win.combo, a$(),doCombo,10,10,120,200

open "Combobox Demo" for window as #win
#win "trapclose Quit"
#win.combo "selectindex 1"

wait

sub Quit handle$
 close #handle$
 end
 end sub

sub doCombo handle$
#handle$ "selection? sel$"
notice "You chose ";sel$
end sub

A combobox demo with branch label event handler and with subroutine event handler.

nomainwin
a$(1) = "one"
a$(2) = "two"
a$(3) = "three"
a$(4) = "four"

combobox #win.combo, a$(),doCombo,10,10,120,200
Button #win, "exit", [Quit], LL, 30,10,120,20
open "Combobox Demo" for window as #win
#win "trapclose Quit"
#win.combo "selectindex 1"

wait

sub Quit handle$
 close #handle$
 end
 end sub

sub doCombo handle$
#handle$ "selection? sel$"
notice "You chose ";sel$
end sub

[Quit]
 close #win
 end

Useful Procedures

' Place a useful function using this keyword here