HeaderPane
Main
Hide
Share Link
Print

CalcOptimalColumnWidth

Calculates a column's optimal width so text and pictures are not clipped.

C

int WINAPI SftBox_CalcOptimalColumnWidth(HWND hwndCtl, int iCol, LONG maximum);

C++

int CSftBox::CalcOptimalColumnWidth(int iCol, LONG maximum) const;

Parameters

hwndCtl

The window handle of the combo box control.

iCol

The zero-based column number whose optimal width is to be calculated.

maximum

Defines the maximum number of items to be considered for width calculation. Specify a number less than or equal to 0 to consider all items. If a combo box control contains many items, scanning all items may be extremely slow, as each cell's width needs to be calculated. Using an application defined maximum number, the calculation can be limited to maximum items. This results in better response time, yet some items which are not within the number of scanned items may still be clipped.

Returns

Returns the optimal column width in pixels. The return value is -1 if an error occurred.

Comments

The CalcOptimalColumnWidth function calculates a column's optimal width so text and pictures are not clipped.

CalcOptimalColumnWidth returns the optimal width of a specified column so that the column header's and each cell's text and picture can be completely displayed without being truncated or clipped, in the dropdown portion and in the static portion of the combo box control. The column width can be changed using SetColumns. MakeColumnOptimal can be used to set a column's optimal width without having to calculate it first.

Only visible items are considered. Items which are not visible because their parent items are collapsed are not included in the width calculation.

By changing combo box control item attributes, the optimal column width may change. Adding items, setting new cell texts and changing cell text are a few of the actions that can affect the optimal column width. The column width may have to be set again to allow items to be completely visible. The combo box control does not automatically adjust column widths.

Individual cells can be ignored from optimal column width calculation by setting the SFTBOXCELL_IGNORE value in the flag2 member of the SFTBOX_CELL structure. In a combo box control using a virtual data source, items can be excluded by setting the SFTBOXITEM_IGNORE value in the flag2 member of the SFTBOX_ITEM structure.

See Also C/C++ API | Categories | Notifications


Last Updated 11/21/2026 - (email)
© 2026 Softel vdm, Inc.