Renaming a List View Item

In my namespace extension I have used ListView_EditLabel for renaming an
item. I need help in handling LVN_BEGINLABELEDIT and LVN_ENDLABELEDIT
notifications. What is happening right now is very weird. As soon as I
invoke ListView_EditLabel through my context menu, an edit box opens around
the item's highlighted name but does not display a flashing cursor for
editing the name. Instead it just stays that way for a few seconds and then
the edit box disappears on its own and the item remains unchanged with the
original name. What do I need to do in the two notifications so as to
implement shell's standard renaming procedure?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nadirkamalAuthor Commented:
Adjusted points to 80
What's about ListView_SetItemText()?
Assume hWin is the handle of the listview control.

To edit,


Make sure that you are not later changing the focus (for example, by SetForegroundWindow(), or by creating a new window).
Once the edit box looses the focus, it cancels the edit operation.

Parent window of hWin must handle WM_NOTIFY message
(use <// or> code if the parent window is a dialog box).

LRESULT ParentWindowProc(HWND hWnd,....)
// or BOOL ParentDialogProc(HWND hDlg,...)

switch(uMsg) {


  if(h->code==LVN_BEGINLABELEDIT) {
      // Return FALSE to allow editing.
      return FALSE;  
      // or SetWindowLong(hDlg,DWL_MSGRESULT,FALSE); return TRUE;
  if(h->code==LVN_ENDLABELEDIT) {
    if(di->item.pszText) {
      // Successful. Return TRUE to accept.
      return TRUE;
      // or SetWindowLong(hDlg,DWL_MSGRESULT,TRUE); return TRUE;
    else {
      // Cancelled. Return value doesn't matter.
      return 0;
      // or return FALSE;
return DefWindowProc(hWnd,...);
// or return FALSE;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.