User Tools

Site Tools


multi-column_20list_20boxes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

multi-column_20list_20boxes [2018/03/31 13:19]
127.0.0.1 external edit
multi-column_20list_20boxes [2018/04/15 17:25] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Multi-column list boxes===== =====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%20View%20with%20tooltips|List View with tooltips]] and the [[http://​www.bbcbasic.co.uk/​bbcwin/​examples/​dirprint.html|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:\\ \\ +//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%20View%20with%20tooltips|List View with tooltips]] and the [[http://​www.bbcbasic.co.uk/​bbcwin/​examples/​dirprint.html|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: 
 + 
 +<code bb4w> ​
         INSTALL @lib$+"​WINLIB2"​         INSTALL @lib$+"​WINLIB2"​
         LBS_SORT = 2         LBS_SORT = 2
Line 23: Line 25:
         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Dog"​+tab$+"​6"​+tab$+"​Cass"​         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Dog"​+tab$+"​6"​+tab$+"​Cass"​
         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Gerbil"​+tab$+"​1"​+tab$+"​Gizmo"​         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:\\ \\ +</​code>​ 
 +         
 +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: 
 + 
 +<code bb4w>
         INSTALL @lib$+"​WINLIB2"​         INSTALL @lib$+"​WINLIB2"​
         LBS_SORT = 2         LBS_SORT = 2
Line 46: Line 52:
         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Dog"​+tab$+"​6"​+tab$+"​Cass"​         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Dog"​+tab$+"​6"​+tab$+"​Cass"​
         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Gerbil"​+tab$+"​1"​+tab$+"​Gizmo"​         SYS "​SendDlgItemMessage",​ !dlg%, 101, LB_ADDSTRING,​ 0, "​Gerbil"​+tab$+"​1"​+tab$+"​Gizmo"​
 +</​code>​
 +
 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 [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnlistbox|FN_listbox]] should be set to **"​LBS_USETABSTOPS"​**. Dimensions are specified in pixels rather than dialogue box units. 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 [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnlistbox|FN_listbox]] should be set to **"​LBS_USETABSTOPS"​**. Dimensions are specified in pixels rather than dialogue box units.
multi-column_20list_20boxes.txt · Last modified: 2018/04/15 17:25 by richardrussell