Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 21: Tree and List Controls


argument is 0 if the item will be the leader. The lpszItem value is the string that will be
used to lead the current item.

21.3.4..The Report View.................................................................................


Whether you use the first or the second version, the InsertItem() method allows you to
create the item that will display for the Icon, the Small Icon, or the List views of the
control. If you plan to display the list in Report view (or to allow the user to transition
from various views) and you want to provide more information for each item, you must
“create” a report of information for each item.

Among the possible views available for a list control, one of them can display columns.
This view is called the report view. This view is not required for a list view but it is the
only one that provides more detailed information about the items of the list. If you plan to
display that view on your list control, then you should create columns. (Alternatively, you
can omit creating columns and instead provide headers of columns separately, which can
be done using the CHeaderCtrl class. Otherwise, the list control provides the means of
creating columns for its report view.)

To create the column(s) of a list control, you can use the CListCtrl::InsertColumn()
method. One of its syntaxes is:

int InsertColumn(int nCol, const LVCOLUMN* pColumn);

The nCol argument is the index of the column that this call will create.

The pColumn argument is an LVCOLUMN pointer. This structure is defined as follows:

typedef struct _LVCOLUMN {
UINT mask;
int fmt;
int cx;
LPTSTR pszText;
int cchTextMax;
int iSubItem;
#if (_WIN32_IE >= 0x0300)
int iImage;
int iOrder;
#endif
} LVCOLUMN, FAR *LPLVCOLUMN;

The mask member variable is used to specify what attribute of the column you want to
define with this LVCOLUMN variable.

The fmt member variable formats the text of the column. For example, it can be used to
align the text of the column to the left (the default) (LVCFMT_LEFT), the center
(LVCFMT_CENTER), or the right (LVCFMT_RIGHT). If you do not set a value for
this member variable, the text will be aligned to the left. If you plan to set a value for this
variable, then add the LVCF_FMT value for the mask member variable.

The cx variable is used to specify the width occupied by the text of the column. If you do
not set a value for this property, the column would initially appear so narrow its text
would not display. Therefore, unless you have a good reason to omit it, you should
always specify the value of this variable. If you plan to set a value for this property, then
add the LVCF_WIDTH value to the mask member variable.
Free download pdf