A SftBox/DLL combo box control can display one or more columns. Each column has its own width, text alignment, colors and title. All columns are defined at once using the SetColumns function and an array of SFTBOX_COLUMN structures, one for each column. The column definitions apply to the entire combo box, the dropdown portion and the static portion always use the same columns, widths and column order.
The SFTBOX_COLUMN structure has many members, most of which are optional. Clear the structure, then set the members needed. Color members set to SFTBOX_NOCOLOR use the default colors.
static void InitColumn(LPSFTBOX_COLUMN lpCol, int position, int width, LPCTSTR lpszTitle) { memset(lpCol, 0, sizeof(SFTBOX_COLUMN)); lpCol->width = width; /* column width in pixels */ lpCol->style = ES_LEFT; /* cell text alignment */ lpCol->styleTitle = ES_LEFT; /* column header text alignment */ lpCol->lpszTitle = (LPTSTR) lpszTitle; /* column header text */ lpCol->colorBg = lpCol->colorFg = lpCol->colorBgSel = lpCol->colorFgSel = SFTBOX_NOCOLOR; lpCol->colorBgEnd = lpCol->colorBgSelEnd = SFTBOX_NOCOLOR; lpCol->colorProgress = lpCol->colorProgressEnd = SFTBOX_NOCOLOR; lpCol->realPos = lpCol->dispPos = position; /* display position */ } SFTBOX_COLUMN aCols[3]; InitColumn(&aCols[0], 0, 100, TEXT("State")); InitColumn(&aCols[1], 1, 40, TEXT("Abbr.")); InitColumn(&aCols[2], 2, 100, TEXT("Capital")); SftBox_SetColumns(hwndBox, 3, aCols);
The style member defines the alignment of the cell text in the column (ES_LEFT, ES_CENTER or ES_RIGHT), which individual cells can override using SetCellInfo. It also enables multiple text lines (SFTBOX_MULTILINE, SFTBOX_WRAP, see Multi-Line Cell Text) and cell ToolTips (SFTBOX_TOOLTIP, see ToolTips). The styleTitle member defines the alignment of the column header text.
The text of a cell is defined using SetText, with the item index and the column number. AddString and InsertString define the text of column 0.
GetColumns returns the number of columns and a pointer to an array with the current column definitions. The array is owned by the combo box and must not be freed. It is only valid until the next call to GetColumns, SetColumns or MakeColumnOptimal, so it must be retrieved again each time it is needed. To change a column attribute, retrieve the array, change the member and call SetColumns with the same array.
LPSFTBOX_COLUMN lpCol; int nCols = SftBox_GetColumns(hwndBox, &lpCol); if (nCols > 1) { lpCol[1].width = 60; SftBox_SetColumns(hwndBox, nCols, lpCol); }
To replace a column title in the array returned, replace the lpszTitle pointer. The string it points to must not be modified. A column title can also be changed using SetHeader.
In a simple combo box or dropdown combo box, SetColumns creates a new edit control (the SFTBOXN_EDITCREATED notification is sent).
A column width is defined in pixels using the width member. A column with a width of 0 is not visible. MakeColumnOptimal sets the width of one column or of all columns (-1) so the cell text, pictures and the column header are completely visible. CalcOptimalColumnWidth calculates this width without changing the column. Both functions consider the items that are present, so they are called after the items have been added.
SftBox_MakeColumnOptimal(hwndBox, -1, 0); /* make all columns optimal */ SftBox_RecalcHorizontalExtent(hwndBox, 0); /* update the horizontal scrolling extent */
The last displayed column can be an open-ended column (SetOpenEnded), which is the default. An open-ended last column uses at least its defined width or all the space remaining up to the right edge. If the last column is not open-ended, it uses its defined width and text which does not fit is truncated.
Users can resize columns (see Column Resizing) and change the column order (see Column Reordering) using the column headers. An application always uses the same column numbers, regardless of the order in which the columns are displayed (see Display vs. Real Columns).
In a dropdown list combo box, the static portion displays the selected item with the cells of all columns, using the same column widths, column order and horizontal scrolling offset as the dropdown portion.
In a simple combo box or dropdown combo box, the edit control portion displays the cell text of one column only. SetEditSearchColumn defines this column. If it is set to -1, the first displayed column is used. The same column is searched as the user types text into the edit control portion.