Question

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.

No correct solution

OTHER TIPS

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top