preventing editing of List View item's label

This is a discussion on preventing editing of List View item's label within the Windows Programming forums, part of the Platform Specific Boards category; How do I prevent user from editing a List View item's label? MSDN says that it can be done by ...

  1. #1
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96

    preventing editing of List View item's label

    How do I prevent user from editing a List View item's label? MSDN says that it can be done by returning TRUE in response to a LVN_BEGINLABELEDIT notification. But this doesn't work. I have following code
    Code:
    switch(msg) {
      case WM_NOTIFY:
        if (((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT) {
          return TRUE;
        }
        break;
    }
    in my modeless dialog box (with a List View control) procedure.
    Last edited by larry; 02-13-2003 at 04:37 AM.
    Please excuse my poor english...

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    What is "code?"

    Code:
    reinterpret_cast<LPNMLVDISPINFO>(lParam)->hdr->code == LVN_BEGINLABELEDIT
    Kuphryn

  3. #3
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    [B]NMHDR[/B}

    Contains information about a notification message.

    Code:
    typedef struct tagNMHDR { 
        HWND hwndFrom; 
        UINT idFrom; 
        UINT code; 
    } NMHDR;
    Members

    hwndFrom
    Window handle to the control sending a message.

    idFrom
    Identifier of the control sending a message.

    code
    Notification code. This member can be a control-specific notification code or it can be one of the common notification codes.
    The problem is, that the control doesn't react to values I return, not the notificiation message itself.
    Please excuse my poor english...

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Try removing the LVS_EDITLABELS style when you create the control.

    or try

    Code:
    LView = (NM_LISTVIEW FAR *) lParam;
    if(LVN_ENDLABELEDIT==LView->hdr.code)
    as this cast no longer seems to work

    if (((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    Thanks, but I probably didn't express myself clearly. I want only some labels to be uneditable, not all of them, so the LVN_BEGINLABELEDIT style is not going to help me, because it defines the behavior of all the labels.

    Also LVN_ENDLABELEDIT notification message isn't the right thing, because it's raised after user edited the label and that's what I want to avoid.

    I have to use LVN_BEGINLABELEDIT, but it doesn't care what I return as a response to it, although it should. I use VC++ 6.0 and W2k.

    For better image, the List View Control is supposed to be a listing of items, whose names can user edit, except the first item, which is "Insert new item."

    as this cast no longer seems to work
    if (((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT)
    I don't think so, it works well, the notification is raised.
    Please excuse my poor english...

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>if (((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT)


    This is an incorrect cast. It happens to work now as the first element of the NM_LISTVIEW struct is a NMHDR struct. Will not work if MS changes this struct.

    Do you mean you want all the first items (in column zero) uneditable, which realy negates the edit lables style?

    Or

    You want the first row (or first item in the first row) to be uneditable?

    Try to intercept all messages to the first row and discard.

    if you want a listview where all the items are editable (except the first) then you will need to write your own with a subclassed wndproc. Just create an edit in the right cell.

    I have written one for WIN32 in C but is too complicated to post. Let me know.
    Last edited by novacain; 02-19-2003 at 07:47 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    As for the typecast, I don't think MS is going to change the NMHDR structure, because it's the LPARAM of WM_NOTIFY message, one of the most essential messages. They'd more likely change the NMLVDISPINFO structure sooner.

    Nevermind. The topic is editing a label. If I understand you right, you also didn't make out trying to disable a label on single item using a LVN_BEGINLABELEDIT return value. So they kind of forgot to implement it??

    I thought creating my own List View is the last solution, but it seems to be the only one

    I'd really welcome if you send me your code. I'd use it as a reference if something goes wrong, but probably not copy it, because my program is in C++.

    Thanks in advance.

    P.S. It seems the forum email system doesn't allow attachments, so here's the address: larrycz@atlas.cz.
    Last edited by larry; 02-22-2003 at 03:14 AM.
    Please excuse my poor english...

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 11:30 AM
  3. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 06:29 PM
  4. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21