Edit Text of a List Control In MFC

  • create the list with the LVS_EDITLABELS style
  • set a dialog control on your list if it does not have one, eg SetDlgCtrlID( ID_EDITLABEL );
  • you might need some code for tracking the current selection
  • create the edit in a messagehandler reacting on a click/doubleclick or other user input (seems you have that covered already), best to put this in the parent class.
  • add a handler for the edit end in the parent class

ON_NOTIFY( LVN_ENDLABELEDIT, ID_EDITLABEL, OnEndEdit )


void MyParentClass::OnEndEdit( NMHDR* pNMHDR, LRESULT* pResult )
{
  NMLVDISPINFO* pLVDI = reinterpret_cast< NMLVDISPINFO* >( pNMHDR );
  if( pLVDI->item.pszText )
    m_List.SetItemText( m_iCurrentSelection, 0, pLVDI->item.pszText );
  *pResult = 0;
}
Posted in Uncategorized | Leave a comment