How do I make a TCheckListBox scroll vertically? - delphi

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?

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.)

Related

Firemonkey TListView - Adjust item text margins

I'm implementing a TListView in a Firemonkey app, where the height of each list item must be as small as possible, just large enough to fit the text. However, there is an apparent margin on the top of the text, leaving an empty space at the beginning of each list item.
The item appearance is set to ListItemRightDetail, but I cannot find any properties anywhere to allow me to control this - neither in the FMX design or the Styles for the List View.
How do I eliminate the margin at the top of list item text so that I can minimize the list item heights?
There are not necessarily any "margin" properties, as this margin is pretty much built-in. However, this can be adjusted by modifying the PlaceOffset.Y property, and making them a negative value. This will "lift up" the contents within each list item. I find -3 to be a sufficient amount to reduce this margin...
ListView1.ItemAppearanceObjects.ItemObjects.Text.PlaceOffset.Y := -3;
ListView1.ItemAppearanceObjects.ItemObjects.Detail.PlaceOffset.Y := -3;

(Auto Fit All Columns) of ListGrid's Context Menu stretches the Row number in SmartGWT

I'm not sure whether this should be the expected behaviour or is a bug.
When the Row Number column is set to be shown, selection of (Auto Fit All Columns) from context menu stretches the column
to the end of the ListGrid.
I though there is an issue in our app but the ShowCase has (Grids > Appearance > Row Numbering)
the same problem.
final ListGrid countryGrid = new ListGrid();
countryGrid.setWidth(500);
countryGrid.setHeight(224);
countryGrid.setShowAllRecords(true);
countryGrid.setShowRowNumbers(true);
If you change the width of a column before applying the Auto fit it behaves normally.
Has someone had the same issue ever?
Is there any workaround?
Without looking further at your code (for instance, other width and autofit related configurations applied to the list grid, field types and expected contents) it's difficult to know if this is expected behavior. Although I agree, by looking at the demo, that it is at least strange behavior.
But this is what I do in my ListGrids to keep the row numbers at the size I want:
// this field is created only as a way to define the row number field properties
ListGridField rowNumberFieldProps = new ListGridField();
rowNumberFieldProps.setWidth(50);
rowNumberFieldProps.setCanAutoFitWidth(true);
rowNumberFieldProps.setAutoFitWidthApproach(AutoFitWidthApproach.VALUE);
grid.setRowNumberFieldProperties(rowNumberFieldProps);
grid.setShowRowNumbers(true);
Some notes:
Since I expect a lot of records to be displayed (and in consequence, large row numbers), I use a row number column width that fits properly my numbers (50 in my case).
Notice that setCanAutoFitWidth(false) will leave your row number field fixed in size, even when 'Auto Fit All Columns' is used. This is probably a good approach in your case. If you do that, you can simply remove the line with setAutoFitWidthApproach.
setCanAutoFitWidth(true) and setAutoFitWidthApproach help me control what happens when I use the 'Auto Fit All Columns' context menu. In my case I do want autofitting to apply to extend the column width when I have row numbers beyond 99.999 (not the most common case for me, but possible).

Highcharts: How to adjust size of bar chart with respect to spacing/size of bars?

I have a bar graph (note: the length of a bar spans horizontally. conversely, a column graph spans vertically. See below.) My series data can either become a long list or a short list so the number of bars varies between many and few. If I have many bars, my graph needs more height to maintain the same space between bars and maintain the width of the bars. How can I set the height of the graph to ensure that these are fixed?
I looked into a scrollbar for the vertical axis, but I didn't like this because the browser may have it's own vertical scrollbar. I also found advice on dynamically resizing the graph to fit the window, but this is won't work if I have more bars than would fit within a maximized window. So I think the best idea would be to have a graph that sizes with the number of bars. If the bar graph is greater than the page height, the browser's vertical scrollbar will come into action.
Bar graph:
===
==========
=============== ]---- width of bars needs to be maintained.
[spacing between bars also needs to be maintained.]
=======
===========
=== <--- a new bar would simply go here, and chart would increase height by 1 bar width.
The best solution that I have found for this is to determine the size by a simple count of the categories I will need on the server side.
When loading the page, I start with the height needed for the chart's top and bottom margin.
I do a count of my data, and multiply by however much space I need (usually 20, 25 pixels per category, in my cases).
Then set the height of the container accordingly.
I usually do this with php on page load. I'm sure a javascript implementation wouldn't be difficult to achieve.

removing space around components in blackberry

I have a gui that keeps scrolling on the 8520 screen. I have used setPadding(XYEdges) and setMargin(XYEdges) to remove the spaces around the components on the UI but there's still space left in between these components. Are there other API calls i can make to remove spaces around components?
You need to consider the following:
setPadding refers to a boundary inside the border of a field and controls how close the internal content of the field can be to the border.
setMargin refers to a boundary outside the border of a field and controls how close the field can be to an adjacent field on that edge.
BUT note that the margins of adjacent fields overlap, so that if field A has it's right margin set to 0, and right adjacent field B has it's left margin set to 20, then the two fields will still be placed no closer than 20 pixels apart.
i.e. you have to take into account the margins set for the edges of all adjacent fields.
Returning to padding, the same applies for managers if you set their internal padding. This will determine how close to the inside of the manager's border an included field can be placed.
Somewhere in the blackberry documentation and/or support forum, there is a document explaining this pictorially, I just can't find my link to it right now, but will post it here when I find it again.

Scrolling the TStringGrid pixel by pixel

Scrolling a TStringGrid using its horizontal scroll bar will scroll a column at a time. In some situations, this creates a really nasty behavior that makes the grid unusable: if the width of last column is large (example, 1000 pixels) the user won't be able to scroll the grid to see the entire content of the column.
There is a way to scroll by pixel? Or to set the correct scroll range for grid's scroll bar?
As far as I know, no you can't horizontally scroll the string or draw grids by pixels, only by whole columns. I agree it can be a problem by the way. I tend to autosize the columns but make the max initial size of any column be slightly less than the clientwidth of the control.
I have looked into the source code. With Borland's code it can't be done.
However, Lazarus has this capability.

Resources