How to scroll vertically in a TCheckListBox?

I have a TCheckListBox in the form. The Columns property is set to 2, and if there are more items than two columns can fit on the screen, it places a horizontal scroll bar at the bottom of the control.

The fact is, how this form was laid out, it would be much more convenient to scroll vertically. But I can’t figure out how to do this. I thought setting columns to 1 should work, but it is not.

Does anyone know how to scroll TCheckListBox vertically, not horizontally?

+4
source share
1 answer

You need to set Columns to 0.

For all positive values, VCL sends an LB_SETCOLUMNWIDTH message to the main list control, with the width parameter set to the width of the list client 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 will become visible.

If Columns is 0, then there is one column that spans the entire width of the client in the list, and elements that do not fit will be displayed with a vertical scroll bar and hide the horizontal scroll bar.

Edit:

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

The TCustomListBox.CreateParams() method sets the style of the LBS_MULTICOLUMN list LBS_MULTICOLUMN depending on the Columns property other than 0. The style flag is set for negative values, but VCL does not send the LB_SETCOLUMNWIDTH message LB_SETCOLUMNWIDTH so the built-in control uses the default column width. documented :

15 times the average font width for the font used in the list.

(Search "LBS_MULTICOLUMN Style Defines" to find the appropriate passage of text.)

+6
source

Source: https://habr.com/ru/post/1301760/


All Articles