INFO: Multicolumn List Boxes in Microsoft Windows

ID: Q64504


The information in this article applies to:


SUMMARY

In the Microsoft Windows environment, a multicolumn list box is designed to contain homogeneous data. For example, all the data might be "first names." These first names could logically fall into the same column or be in multiple columns. This feature was added to Windows at version 3.0 to enable a list box to be shorter vertically by splitting the data into two or three columns.


MORE INFORMATION

To create a multicolumn list box, specify the LBS_MULTICOLUMN style when creating the list box. Then the application calls the SendMessage function to send an LB_SETCOLUMNWIDTH message to the list box to set the column width.

When an application sends an LB_SETCOLUMNWIDTH message to a multicolumn list box, Windows does not update the horizontal scroll bar until the a string is added to or deleted from the list box. An application can work around this situation by performing the following six steps when the column width changes:

  1. Send the LB_SETCOLUMNWIDTH message to the list box.


  2. Send a WM_SETREDRAW message to the list box to turn off redraw.


  3. Add a string to the list box.


  4. Delete the string from the list box.


  5. Send a WM_SETREDRAW message to the list box to turn on redraw.


  6. Call the InvalidateRect function to invalidate the list box.


In response, Windows paints the list box and updates the scroll bar.

Windows automatically manages the list box, including horizontal and vertical scrolling and distributing the entries into columns. The distribution is dependent on the dimensions of the list box. Windows fills Column 1 first, then Column 2, and so on. For example, if an application has a list box containing 13 ordered items and vertical space for 5 items, items 1-5 would be in the first column, items 5-10 in the second, and 11-13 in the last column, and item order would be maintained.

A multicolumn list box cannot have variable column widths.

Additional query words: WIN16SDK


Keywords          : kbCtrl kbListBox kbNTOS kbGrpUser kbWinOS 
Version           : 
Platform          : 
Issue type        : kbinfo 

Last Reviewed: March 5, 1999