CListCtrl::SetItemText This method changes the text of a list view item or subitem. BOOL SetItemText( int nItem, int nSubItem, LPCTSTR lpszText ); Parameters nItem Specifies the index of the item whose text is to be set. nSubItem Specifies the index of the subitem, or zero to set the item label. lpszText Specifies the pointer to a string that contains the new item text. Return Value Nonzero if it is successful; otherwise, it is zero.Example // Pointer to the list view control. CListCtrl* pmyListCtrl;CString strText; int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();// Insert 10 items in the list view control. for (int i=0;i < 10;i++) { strText.Format(TEXT("item %d"), i); // Insert the item, select every other item. 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++) { strText.Format(TEXT("sub-item %d %d"), i, j); pmyListCtrl->SetItemText(i, j, strText); } }
This method changes the text of a list view item or subitem. BOOL SetItemText(
int nItem,
int nSubItem,
LPCTSTR lpszText );
Parameters
nItem
Specifies the index of the item whose text is to be set.
nSubItem
Specifies the index of the subitem, or zero to set the item label.
lpszText
Specifies the pointer to a string that contains the new item text.
Return Value
Nonzero if it is successful; otherwise, it is zero.Example
// Pointer to the list view control.
CListCtrl* pmyListCtrl;CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i); // Insert the item, select every other item.
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++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
第一个参数为nItem,指定某一行啊
先InsertItem再SetItemText
GetNexSelectedItem()
因为每行nItem 是会变的(因为在增加或删除时,nitem会变)
用什么可以作为一行数据唯一标识(比如每行数据是存储数据的的结构的指针),在我要修改该行数据时,直接找到该行数据,而不用去查找