User Tools

Site Tools


multi-column_20list_20boxes

Multi-column list boxes

by Richard Russell, October 2006

If you want to display a list of items in a multiple-column format the best way is probably to use a list view control: that provides facilities for column headers, column dividers, user-adjustable column widths, sorting-by-column etc. See List View with tooltips and the DIRPRINT program for examples of list view controls implemented in BBC BASIC for Windows.

However in some situations a list view control may be over-complicated. A simpler technique is to use an ordinary Windows list box. By default list boxes do not support tabulation to a particular column but you can enable that feature. There are two options available: setting all the columns to be the same width or specifying an explicit horizontal position for each tab stop.

The code below is a complete example program illustrating the use of a dialogue box containing a multiple-column list box, with all columns the same width:

        INSTALL @lib$+"WINLIB2"
        LBS_SORT = 2
        LBS_USETABSTOPS = &80
        LB_ADDSTRING = 384
        LB_SETTABSTOPS = 402
 
        dlg% = FN_newdialog("Dialogue box", 20, 20, 160, 120, 8, 200)
        PROC_listbox(dlg%, "", 101, 10, 10, 140, 100, LBS_USETABSTOPS-LBS_SORT)
 
        PROC_showdialog(dlg%)
 
        DIM tab{wid%}
        tab.wid% = 50
        SYS "SendDlgItemMessage", !dlg%, 101, LB_SETTABSTOPS, 1, tab{}
 
        tab$ = CHR$9
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Animal"+tab$+"Age"+tab$+"Name"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, ""
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Cat"+tab$+"16"+tab$+"Henry"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Dog"+tab$+"6"+tab$+"Cass"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Gerbil"+tab$+"1"+tab$+"Gizmo"

The structure member tab.wid% determines the width of the columns, in dialogue box units; here it is set to 50. The TAB character (CHR$9) is used to separate the contents of the different columns in the strings written to the list box. Note that the last parameter of PROC_listbox enables the use of tabs and disables sorting.

To specify an explicit position for each tab stop the code must be modified as follows:

        INSTALL @lib$+"WINLIB2"
        LBS_SORT = 2
        LBS_USETABSTOPS = &80
        LB_ADDSTRING = 384
        LB_SETTABSTOPS = 402
 
        dlg% = FN_newdialog("Dialogue box", 20, 20, 160, 120, 8, 200)
        PROC_listbox(dlg%, "", 101, 10, 10, 140, 100, LBS_USETABSTOPS-LBS_SORT)
 
        PROC_showdialog(dlg%)
 
        ntabs% = 2
        DIM tabs{pos%(ntabs%-1)}
        tabs.pos%(0) = 50 : tabs.pos%(1) = 80
        SYS "SendDlgItemMessage", !dlg%, 101, LB_SETTABSTOPS, ntabs%, tabs{}
 
        tab$ = CHR$9
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Animal"+tab$+"Age"+tab$+"Name"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, ""
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Cat"+tab$+"16"+tab$+"Henry"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Dog"+tab$+"6"+tab$+"Cass"
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Gerbil"+tab$+"1"+tab$+"Gizmo"

Here the variable ntabs% contains the number of tab stops wanted; in this case 2. The integer array tabs.pos%() contains the positions of the tab stops, in dialogue box units. Here the first column is the same width as before (50 units) but the second column is narrower (30 units).

A similar technique can be used for a list box on the main output window rather than in a dialogue box. In that case you will need to use SendMessage rather than SendDlgItemMessage and the style value used in FN_listbox should be set to “LBS_USETABSTOPS”. Dimensions are specified in pixels rather than dialogue box units.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
multi-column_20list_20boxes.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1