如何从源listctrl 复制到目的listctrl,要求 :字段内容,行高,字段宽完全一样?

解决方案 »

  1.   

    将这些属性从源ListCtrl中读出,再设置到新的ListCtrl中。
      

  2.   

    将源LIST的内容写到一个结构相同的数组中,然后把数组中的内容写入目的LIST就可以了
      

  3.   

    将源LIST的内容写到一个结构相同的数组中,然后把数组中的内容写入目的LIST就可以了
      

  4.   

    for example:
    void CSortListCtrl::CopyItem()
    {
    int iSel, iCurr, i, j; m_Copynum = 0;
    m_PasteFlag = 1; // copy flag
    iSel = CListCtrl::GetSelectedCount();
    m_Copynum = iSel;
    if (iSel > MAX_COPYNUM)
    {
    MessageBox("The num of you copy is so large!","Phonebook Copy");
    return;
    }

    POSITION pos = CListCtrl::GetFirstSelectedItemPosition();
    for (i=0; i<iSel; i++)
    {
    iCurr = CListCtrl::GetNextSelectedItem(pos);
    m_CopyInfo[i] = _T("");
    for (j=0; j<m_iNumColumns; j++)
    {
    m_CopyInfo[i] +=  CListCtrl::GetItemText(iCurr, j) + "\t";
    }
    }
    }void CSortListCtrl::PasteItem()
    {
    LV_ITEM lvItem;
    int i, iItem, nWord;
    UINT nPos, oldPos;
    CIVStringSet m_setstrings;
    CString strText[MAX_ITEMNUM], buf;
    char * text;

    m_setstrings.Add("\t");
    if (m_Copynum == 0)
    {
    return;
    }
    else
    {
    for (i=0; i<m_Copynum; i++)
    {
    iItem = 0;
    nPos = m_setstrings.FindFirstIn(m_CopyInfo[i], nWord);
    if (nPos != 0xFFFFFFFF)
    {
    do
    {
    if (iItem == 0)
    {
    strText[iItem] = m_CopyInfo[i].Left(nPos);
    }
    else
    {
    buf = m_CopyInfo[i].Left(nPos);
    strText[iItem] = buf.Right(nPos-oldPos-1);
    }
    iItem++;
    oldPos = nPos;
    nPos = m_setstrings.FindNext(nWord);
    }
    while (nPos != 0xFFFFFFFF);
    // additem
    text = new char[strText[0].GetLength()+1];
    memset(text, 0, strText[0].GetLength()+1);
    sprintf(text, "%s", strText[0]);
    lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
    lvItem.iImage=-1;
    lvItem.iItem =GetItemCount();
    lvItem.iSubItem =0;
    lvItem.pszText = (LPTSTR) text;
    const int iIndex = CListCtrl::InsertItem(&lvItem); LPTSTR* arrpsz = new LPTSTR[ iItem ];
    arrpsz[ 0 ] = new TCHAR[ lstrlen( text ) + 1 ];
    (void)lstrcpy( arrpsz[ 0 ], text );
    delete text;

    for( int iColumn = 1; iColumn < iItem; iColumn++ )
    {
    text = new char[strText[iColumn].GetLength()+1];
    memset(text, 0, strText[iColumn].GetLength()+1);
    sprintf(text, "%s", strText[iColumn]);
    ASSERT_VALID_STRING( text );
    VERIFY( CListCtrl::SetItem( iIndex, iColumn, LVIF_TEXT , text, 0, 0, 0, 0 ) );
    arrpsz[ iColumn ] = new TCHAR[ lstrlen( text ) + 1 ];
    (void)lstrcpy( arrpsz[ iColumn ], text );
    delete text;
    } VERIFY( SetTextArray( iIndex, arrpsz ) );
    }
    }
    }
    if (m_PasteFlag == 2)
    {
    m_Copynum = 0;
    }
    }
      

  5.   

    同意楼上的同志们得到源listctrl的所有信息后,用这些得到的属性设置新的listctrl
    GetColumn()
    GetItemText();然后设置
    SetItemText();
    SetColumn();