请问在向CListCtrl控件中写入数据时怎样控制将数据写入指定的某一行?谢谢

解决方案 »

  1.   

    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);
       }
    }
      

  2.   

    SetItem
    第一个参数为nItem,指定某一行啊
      

  3.   

    写错达
    先InsertItem再SetItemText
      

  4.   

    我是要选中已存在的某一行, 是在指定名称行的后面添加一个项目,比如某一行的“主机名”栏里为“aaaaaa”,现在要在该主机名对应的“IP”栏里插入该主机的IP。不是插入新的一行。关键是怎样选中这一行?
      

  5.   

    GetFirstSelectedItemPosition()
    GetNexSelectedItem()
      

  6.   

    直接SetItemText就可以了啊,第一个参数int nItem,指定哪一行可以先遍力查找“aaaaaa”,找到该行
      

  7.   

    借问 
    因为每行nItem 是会变的(因为在增加或删除时,nitem会变)
       用什么可以作为一行数据唯一标识(比如每行数据是存储数据的的结构的指针),在我要修改该行数据时,直接找到该行数据,而不用去查找
      

  8.   

    setitemdata.getitemdata..你可以自己做个LIST或链表,保存一个ITEM的对照。