Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a TCheckListBox scroll vertically?

I've got a TCheckListBox on a form. Its Columns property is set to 2, and if there are more items than can fit on-screen in two columns, it puts a horizontal scrollbar across the bottom of the control.

Thing is, the way this form it laid out, it would be much more convenient to scroll vertically. But I can't seem to figure out how to make the box do that. I thought setting Columns to 1 should work, but it doesn't.

Anyone know how to make a TCheckListBox scroll vertically instead of horizontally?

like image 746
Mason Wheeler Avatar asked Feb 18 '10 23:02

Mason Wheeler


1 Answers

You need to set Columns to 0.

For all positive values the VCL sends a LB_SETCOLUMNWIDTH message to the underlying native list box control, with the width parameter set to the list box client width divided by the number of columns. Items that don't fit will start a new column with the same column width, so the horizontal scrollbar becomes visible.

If Columns is 0 then there is a single column that spans the entire client width of the list box, and items that don't fit will make the vertical scrollbar visible, and hide the horizontal scrollbar.

Edit:

There seems to be genuine interest what happens when a negative value is used for the Columns property.

The method TCustomListBox.CreateParams() sets the LBS_MULTICOLUMN list box style depending on the Columns property being different from 0. For negative values the style flag is set, but the VCL doesn't send the LB_SETCOLUMNWIDTH message, so the native control uses the default column width. It is documented to be:

15 times the average character width for the font used by the list box.

(Search for "The LBS_MULTICOLUMN style specifies" to find the relevant passage of text.)

like image 179
mghie Avatar answered Sep 24 '22 13:09

mghie