edit CListCtrl

HI,everybody:
I have a simple program regarding listview.
I have already set the style of my listview to LVS_EDITLABELS and I also add message handler like this:

void CMyListCtrl::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
{
        *pResult = TRUE;
}


But after I edit the first column lable,the change aint be saved,it retains  as original.

Why?
I debug and I find the above message handler never be reached .
Please help me,it's very urgent.
Thanks


SFSAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Vinayak KumbarConnect With a Mentor Sr Program ManagerCommented:
Hi,

Fine,

U may be having Ur own class for the CEdit then map the OnKillFocus() to it and add the following code
void CMyEdit::OnKillFocus(CWnd* pNewWnd)
{
      CEdit::OnKillFocus(pNewWnd);

      //Fill the display info and send the end editing of label message to parent      
      CString l_strText;
      GetWindowText(l_strText);

      LV_DISPINFO dispinfo;
      dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
      dispinfo.hdr.idFrom = GetDlgCtrlID();
      dispinfo.hdr.code = LVN_ENDLABELEDIT;

      dispinfo.item.mask = LVIF_TEXT;
      dispinfo.item.iItem = m_iItem;
      dispinfo.item.iSubItem = m_iSubItem;
      dispinfo.item.pszText = LPTSTR((LPCTSTR)l_strText);
      dispinfo.item.cchTextMax = l_strText.GetLength();

      GetParent()->GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo );

      PostMessage( WM_CLOSE );
}

Then in the End... message mapped function put the following code
if(pDispInfo->item.pszText != NULL)
{
SetItemText(pDispInfo->item.iItem, pDispInfo->item.iSubItem, pDispInfo->item.pszText);
}

I have the sample workspace. Is u give me ur emailID, I will send it to U.

Hope this helps.
VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

I dont think this question is so easy.
R u trying to edit the column headers? or the items?.

Pls specify.

VinExpert
0
 
SFSAuthor Commented:
I only try to edit it the the first conlumn of items, I just do experiment from codeguru.
Now I can let the edit box pop up to edit but the problem is after I finish it,the text in the first column back to original text.
I add end... message handler in my clistctrl but it never be reached.
Thanx alot, VinExpert
SFS
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Sorry for the spell mistakes. Give me Ur email ID, I will send the sample workspace to u.

Cheers,
VinExpert
0
 
V_BapatCommented:
No need to use cannon to kill an ant. Try this out:

void CMyListCtrl::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
{
      LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;

      LVITEM lvi;
      m_listctrl.GetItem(&lvi);
      lvi.pszText = pDispInfo->item.pszText;
      m_listctrl.SetItem(&lvi);

      *pResult = TRUE;
}
0
 
V_BapatCommented:
If you want to edit subitems, then think about creating an edit control.
0
 
SFSAuthor Commented:
NO,my dear friends.YOu misunderstand me totally!!
Maybe I didnt make it clear,as I said ,I dont wanna edit the subitem but the first column item,SO it'n unnecessary for me to create an edit box and it should be very easy.
Now my problem is I add the style in resource workplace and I add message handler for endedititem in Cmylistctrl but it seems the handler never be reached,if I add the handler in the dialoge,it be reached,why?
THe other problem is the change never be retained.HOw to?
Thanks
To vinexpert:
thank you and if you 'd like to mail it to me for info,please send the code to
geeboy@163.net
Thanx.
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

I have sent u the sample workspace.

Try it out.

VinExpert
0
 
V_BapatCommented:
>Now my problem is I add the style in resource workplace and I add message handler for endedititem in Cmylistctrl but it seems the handler never be reached,if I add the handler in the dialoge,it be reached,why?

It should reach in your derived list control also.

>The other problem is the change never be retained.HOw to?
To retain the changes, *you* have to make changes using either SetItem or SetItemText. You can make changes as I suggested in my last post. Try it out.

Vicky
0
All Courses

From novice to tech pro — start learning today.