• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 675
  • Last Modified:

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?
0
nadirkamal
Asked:
nadirkamal
1 Solution
 
nadirkamalAuthor Commented:
Adjusted points to 80
0
 
MichaelSCommented:
What's about ListView_SetItemText()?
0
 
NickRepinCommented:
Assume hWin is the handle of the listview control.

To edit,

SetFocus(hWin);
ListView_EditLabel(hWin,iItem);

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) {
....

case WM_NOTIFY:

LPNMHDR h=(LPNMHDR) lParam;
if(h->hwndFrom==hWin)
{
  LPNMLVDISPINFO di=(LPNMLVDISPINFO) lParam;
  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;

0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now