-
December 24th, 2011, 03:45 AM
#1
old problem with CListCtrl::EditLabel
I have looked over many posts and articles on this problem without being able to solve it. I have a CListCtrl created with the following styles:
Code:
DWORD dwListStyle = LVS_REPORT | LVS_SORTASCENDING | LVS_SHOWSELALWAYS | WS_CHILD | WS_VISIBLE | LVS_EDITLABELS ;
When I attempt to edit an entry, it appears to edit just fine, but when I hit return following the edit, the former label reappears.
I have attempted to follow the advice posted by others indicating the need for 'handling' LVN_BEGINLABELEDIT and LVN_ENDLABELEDIT.
http://www.codeguru.com/forum/showth...trl+edit+label
http://www.codeguru.com/Cpp/controls...icle.php/c897/
My attempts to do this look like this:
Code:
// in class header
//..
CListCtrl m_MyListCtrl;
//..
// in class implementation
// void MyClass::Rename()
{
//..
int nItem;
nItem = m_MyListCtrl.GetNextItem(-1, LVNI_SELECTED);
//..
m_MyListCtrl.SendMessage(LVN_BEGINLABELEDIT, 0, 0);
m_MyListCtrl.EditLabel(nItem); // how to make edit permanent ?
m_MyListCtrl.SendMessage(LVN_ENDLABELEDIT, 0, 0);
//..
There are no errors encountered. The label appears to edit properly, but when leaving the item, the old label reappears.
Please help.
Last edited by Mike Pliam; December 24th, 2011 at 03:47 AM.
mpliam
-
December 24th, 2011, 11:15 AM
#2
Re: old problem with CListCtrl::EditLabel
Mike, don't you see a difference between "handling LVN_xxx" and "sending LVN_xxx". In LVN_, N stands for notification. Notifications are control "callback" messages, not command messages.
Did you read this Editing listview subitems using LVM_GETEDITCONTROL that golanshahar recommended there in the link you found?
Best regards,
Igor
-
December 24th, 2011, 04:43 PM
#3
Re: old problem with CListCtrl::EditLabel
Thanks for pointing out my misinterpretation of 'handle'.
Yes, I have read and reread the references noted and have experimented extensively, especially:
Editing listview subitems using LVM_GETEDITCONTROL
By Reg Anderson November 21, 1998
http://www.codeguru.com/Cpp/controls...cle.php/c1077/
You'll notice in the many comments accompanying this article that the method proposed, which is devised using CListView, doesnt work with CListCtrl.
My app is based on a CView with a pane (CWorkspaceWnd) derived from CDockablePane containing a CListCtrl member that does all the heavy lifing. It works fine except that the item edits disappear as noted by myself and many others.
I have tried to add Reg Anderson's ListEditView.h and ListEditView.cpp to my test app, but it will not compile (VS 2010), allegedly not recognizing CListVew as a class. Consequently, a connot substitute the CWorkdspaceWnd member, CListCtrl m_wndWorkspaceList, with CListEditView m_m_wndWorkspaceList. So that approach appears to be a dead end.
My next effort was to add the CLVEdit class of Reg Anderson and implement
Code:
afx_msg void OnEndLabelEdit(NMHDR* pNMHDR,LRESULT* pResult);
afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR,LRESULT* pResult);
}
identical to the method used by Anderson in his CListEditView class. This compiles but the edits still disappear as before. Incidently, I am only interested in editing the item in the first column, not any of the subitems.
I have attached a demo program for anyone interested in trying to get this to work.
Last edited by Mike Pliam; December 24th, 2011 at 07:24 PM.
mpliam
-
December 25th, 2011, 04:18 PM
#4
Re: old problem with CListCtrl::EditLabel
Mike, why don't you use the sample I made for you about a year or two ago?
-
December 26th, 2011, 12:15 PM
#5
Re: old problem with CListCtrl::EditLabel
If you don't want to edit sub-items and don't want to change some other default behavior, the only one notification message to be handled is LVN_ENDLABELEDIT:
Code:
void CEditableListCtrl::OnLvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// If the item label text has been modified...
if(NULL != pDispInfo->item.pszText)
{
//... let's put it in the list!
SetItemText(pDispInfo->item.iItem, 0, pDispInfo->item.pszText);
}
*pResult = 0;
}
Aside notes:
- Every compiler "allegedly not recognize CListVew as a class" just because the header file where CListVew class is defined (<afxcview.h>) is not included; anyhow, here you need CListCtrl and not CListView.
- In my example, I didn't handle LVN_ENDLABELEDIT in the parent window class, but the reflected message (=LVN_ENDLABELEDIT) in a class derived from CListCtrl; this is a little bit more OOP approach; additionaly you may notice that the Wizard will help you more in this case.
-
December 26th, 2011, 06:42 PM
#6
Re: old problem with CListCtrl::EditLabel
Thanks, Ovi. Remarkably simple and effective solution.
I now find that I need to identify the original (pre-edited) item label and have been having trouble doing that. I've tried :
Code:
void CEditableListCtrl::OnLvnBeginlabeledit(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
if(NULL != pDispInfo->item.pszText)
{
//... let's save it for later use
m_csItemText = pDispInfo->item.pszText;
m_csOldName = m_csItemText;
}
*pResult = 0;
}
but obviously I havn't figured out how to get the initial (m_csOldName) because this code invariably leads to m_csOldName as empty.
Appreciate any suggestions.
Last edited by Mike Pliam; December 26th, 2011 at 07:25 PM.
mpliam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|