请问如何使ListCtrl的某行的某项处于编辑状态.程序可得到编辑完后按回车后的结果?

解决方案 »

  1.   

    动态在该单元匡 创建CEdit控件,
      

  2.   

    Examplevoid CMyView::OnInitialUpdate() 
    {
       CView::OnInitialUpdate();
       
       // dynamically create an edit control on the view
       CEdit* pEdit = new CEdit;
       pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
          CRect(10, 10, 100, 100), this, 1);
    }MSDN里面的例子。
    我强烈建议你安装MSDN,可以说出了少数几个超级NB别人离了MSDN编不了VC的
      

  3.   

    好像楼上的说得不是很清楚.我在MSDN里没有找到,请能否全面详细一点,谢谢!
      

  4.   

    先继承CListCtrl和CEdit类,在CListCtrl中响应单击等你需要的事件,在其中显示CEdit,在CEdit中响应失去焦点和回车消息如:void CEditListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
    // TODO: Add your control notification handler code here
    if (EditIt(temp->iItem, temp->iSubItem))
    {
    m_nItem = temp->iItem;
    m_nSubItem = temp->iSubItem;
    }

    *pResult = 0;

    }
    void CEditListCtrl::EditItem(int iItem, int iSubItem)
    {
    #define IDC_EDITCTRL 0x1234 if ((iItem < 0) || (iSubItem < 1) || (iSubItem >= m_nColumns))
    {
    return ;
    } CRect rect; // 编辑框的。
    GetSubItemRect(iItem, iSubItem, LVIR_BOUNDS, rect);
    CRect rcClient;
    GetClientRect(rcClient);
    // 以下设置位置。
    if ((rect.left < 0) || (rect.left > rcClient.right))
    { // 在外。
    ScrollIt(rect.left, 0);
    rect.left -= rect.left;
    }
    else if (rect.bottom > rcClient.bottom)
    {
    ScrollIt(0, rect.bottom);
    this->SetFocus();
    return ;
    }
    else if (rect.bottom <= 20)
    {
    ScrollIt(0, -rect.bottom);
    this->SetFocus();
    return ;
    } rect.right = rect.left + GetColumnWidth(iSubItem);
    if (rect.right > rcClient.right) 
    {
       rect.right = rcClient.right;
    } DWORD dwStyle; // 编辑框的风格。
    dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; CEdit *pEdit = new CMyEditCtrl(iItem, iSubItem, GetItemText(iItem, iSubItem));
    if (pEdit == NULL)
    {
    AfxMessageBox(_T("Memory Exhausted!"));
    exit(1);
    }
    pEdit->Create( dwStyle, rect, this, IDC_EDITCTRL );
    // 文字或数字全部选中。
    pEdit->SetSel(0, -1);
    }
    void CMyEditCtrl::OnKillFocus(CWnd* pNewWnd) 
    {
    CEdit::OnKillFocus(pNewWnd);

    // TODO: Add your message handler code here
    CString strTemp;
    GetWindowText(strTemp);
    LV_DISPINFO lvDispInfo; // 将要显示的信息。 lvDispInfo.hdr.hwndFrom = GetParent()->m_hWnd;
    lvDispInfo.hdr.idFrom = GetDlgCtrlID();
    lvDispInfo.hdr.code = LVN_ENDLABELEDIT;
    lvDispInfo.item.mask = LVIF_TEXT;
    lvDispInfo.item.iItem = m_iItem;
    lvDispInfo.item.iSubItem = m_iSubItem;
    // 按了ESC就显示原来的信息。
    lvDispInfo.item.pszText = m_bIsEsc ? LPTSTR((LPCTSTR)m_strText): LPTSTR((LPCTSTR)strTemp);
    lvDispInfo.item.cchTextMax = m_bIsEsc ? m_strText.GetLength() : strTemp.GetLength(); GetParent()->GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(),
    (LPARAM)&lvDispInfo); // 改吧。
    DestroyWindow();
    }
    void CMyEditCtrl::OnNcDestroy() 
    {
    CEdit::OnNcDestroy();

    // TODO: Add your message handler code here
    // 编辑框在此销毁。
    delete this;
    }
    回车消息,你自己响应。