Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot edit labels in a CListCtrl

I'm building a project with MFC Feature Pack. Is this project I have a window which includes a CView, which includes a CListCtrl-derived object. The object includes the LVS_EDITLABELS flag.

Somehow I cannot edit the CListCtrl icon labels by two-time clicking (not double-clicking) on the icon label. After I select the item with a single click, a second click just flashes the item (button down turns text background to white, button up turns it back to blue) and the edit control never appears.

I reduced this problem to the simplest form, and even with a plain CListCtrl object I cannot edit the labels.

I also found that:

  • This problem occurs in VS2008. It doesn't occur in a similar project built in VS2003.

  • I am able to edit the labels if I build a CListView instead of a CView+CListCtrl.

  • I am also able to edit the labels if I build a CFormView and put the CListCtrl inside the resource dialog.

Here's some code in the simplest form: the .h file:

// vwTerminaisTeste.h
//
#pragma once
// vwTerminaisTeste view

    class vwTerminaisTeste : public CView
{
    DECLARE_DYNCREATE(vwTerminaisTeste)

protected:
    vwTerminaisTeste();           // protected constructor used by dynamic creation
    virtual ~vwTerminaisTeste();

    CListCtrl m_lstTerminais;

protected:
    DECLARE_MESSAGE_MAP()
    virtual void OnDraw(CDC* /*pDC*/);
public:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnSize(UINT nType, int cx, int cy);
};

and the .cpp file:

// vwTerminaisTeste.cpp : implementation file
//

#include "stdafx.h"
#include "vwTerminaisTeste.h"

// vwTerminaisTeste

IMPLEMENT_DYNCREATE(vwTerminaisTeste, CView)
vwTerminaisTeste::vwTerminaisTeste()
{
}

vwTerminaisTeste::~vwTerminaisTeste()
{
}

BEGIN_MESSAGE_MAP(vwTerminaisTeste, CView)
    ON_WM_CREATE()
    ON_WM_SIZE()
END_MESSAGE_MAP()

// vwTerminaisTeste message handlers

void vwTerminaisTeste::OnDraw(CDC* /*pDC*/)
{
    CDocument* pDoc = GetDocument();
}

int vwTerminaisTeste::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_lstTerminais.Create(WS_CHILD | WS_VISIBLE | LVS_EDITLABELS, CRect(0,0,1,1), this, 0);
    m_lstTerminais.InsertItem(0, "Teste", 0);

    return 0;
}

void vwTerminaisTeste::OnSize(UINT nType, int cx, int cy)
{
    CView::OnSize(nType, cx, cy);

    if (IsWindow(m_lstTerminais.GetSafeHwnd()))
        m_lstTerminais.MoveWindow(0, 0, cx, cy);
}

This way I cannot edit labels. To change it to a CListView I simply replaced CView by CListView and m_lstTerminais by GetListCtrl(), and removed the OnCreate and OnSize implementations. That way it worked.

Note: the vwTerminaisTeste is created from a CSplitterWndEx within a CMDIChildWndEx-derived class.

like image 200
djeidot Avatar asked May 16 '26 20:05

djeidot


1 Answers

Well nobody solved this problem but I managed to go around it by changing the CView to a CFormView and building a resource dialog with a ListView control, attaching it to the CListCtrl-derived class.

If anyone still has any suggestions on how could I solve this problem entirely, I'd appreciate them.

like image 133
djeidot Avatar answered May 19 '26 10:05

djeidot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!