InsertItem
MFC中CListCtrl控件加入列表项的函数
InsertItem是用于MFC中CListCtrl控件加入列表项的函数,有Return Value、Parameters、Remarks、Example四项参数。
函数原型
int InsertItem( const LVITEM* pItem );
int InsertItem( int nItem, LPCTSTR lpszItem );
int InsertItem( int nItem, LPCTSTR lpszItem, int nImage );
int InsertItem( UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam );
其中,nItem是控件中行的索引 、lpszItem是控件头的名字。
一般我们用的比较多的是第二种和第三种,其中第三种是建立一个带有头标的项。
作用
用于MFC中CListCtrl控件加入列表项。
参数
第一个参数是节点名
第二个参数是树节点未选中时使用的图标下标,
第三个参数是树节点选中时使用的图标下标,
第四个参数是本节点的父节点,第二、三个参数都是针对树的图像列表而言的。CImageList* SetImageList( CImageList * pImageList, int nImageListType );给树插入图像列表.
Return Value
The index of the new item if successful or -1 otherwise.
Parameters
pItem
Pointer to anLVITEM structure that specifies the item’s attributes, as described in the Platform SDK.
nItem
Index of the item to be inserted.
lpszItem
Address of a string containing the item’s label, or LPSTR_TEXTCALLBACK if the item is a callback item. For information on callback items, see CListCtrl::GetCallbackMask.
nImage
Index of the item’s image, or I_IMAGECALLBACK if the item is a callback item. For information on callback items, see CListCtrl::GetCallbackMask.
nMask
The nMask parameter specifies which item attributes passed as parameters are valid. It can be one or more of the mask values described inLVITEM structure in the Platform SDK. The valid values can be combined with the bitwise OR operator.
nState
Indicates the item's state, state image, and overlay image. See the Platform SDK topics LVITEM for more information andList View Item States for a list of valid flags.
nStateMask
Indicates which bits of the state member will be retrieved or modified. See LVITEM in the Platform SDK for more information.
nImage
Index of the item’s image within the image list.
lParam
A 32-bit application-specific value associated with the item. If this parameter is specified, you must set the nMask attribute LVIF_PARAM.
Remarks
Inserts an item into the list view control.
Example
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount(); // Insert 10 items in the list view control.
for (int i=0;i < 10;i++) {
pmyListCtrl->InsertItem( LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); // Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++) {
pmyListCtrl->SetItemText(i, j, strText); }
}
参考资料
最新修订时间:2023-05-27 22:54
目录
概述
函数原型
参考资料