How to edit cell in listcontrol mfc?

爱⌒轻易说出口 提交于 2021-01-29 22:11:29

问题


I need edit my text in second column and I don't want use MFC grid control. how I can edit cell by kicking on it. please give me simple example.

There what I have:

void CTab1::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, m_LISTC);
}

BEGIN_MESSAGE_MAP(CTab1, CDialogEx)
    ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST1, OnEndEdit)
END_MESSAGE_MAP()


// CTab1 message handlers
BOOL CTab1::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    m_LISTC.InsertColumn(0, L"Buttons", LVCFMT_LEFT,50);
    m_LISTC.InsertColumn(1, L"Time", LVCFMT_LEFT, 50);
    m_LISTC.InsertColumn(2, L"State", LVCFMT_LEFT, 40);

    for (int i = 0; i < 12; ++i)
    {
        CString F;
        F.Format(L"F%d", i + 1);
        m_LISTC.InsertItem(m_LISTC.GetItemCount(), F, -1);
        int row = 1;
        int col = 10;
        m_LISTC.SetItemState(row, col, m_LISTC.GetItemState(row, col) | LVN_ENDLABELEDIT);
    }
    return TRUE;
}

void CTab1::OnEndEdit(NMHDR* pNMHDR, LRESULT* pResult)
{
    NMLVDISPINFO* pLVDI = reinterpret_cast< NMLVDISPINFO* >(pNMHDR);
    if (pLVDI->item.pszText)
        m_LISTC.SetItemText(1, 0, pLVDI->item.pszText);
    *pResult = 0;
}

but it not working. so I still can edit cell's of second column.


回答1:


Unfortunately it isn't possible to utilize LVS_EDITLABELS and LVN_ENDLABELEDIT for editing other columns than the first.

I just must create edit control on that cell...



来源:https://stackoverflow.com/questions/20169344/how-to-edit-cell-in-listcontrol-mfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!