Disabling a listitem

This is a discussion on Disabling a listitem within the Windows Programming forums, part of the Platform Specific Boards category; Is there a way of disabling certain elements in a listview(report style)? For instance: If the list has 6 items, ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Disabling a listitem

    Is there a way of disabling certain elements in a listview(report style)?
    For instance:
    If the list has 6 items, i want to disable no. 2 & 4

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    In WIN32

    The LV will send msg's to its parents callback (the hwndparent param in the CreateWindow() call)

    The LV will send WM_NOTIFY msg's
    test the control ID in the wparam to ensure is right control

    Code:
    NM_LISTVIEW	*LView;
    LView = (NM_LISTVIEW FAR *) lParam; 
    
    //the row clicked is LView->iItem, process
    in MFC

    add a LVN_ITEMCHANGING handler and do the same



    In both cases

    return FALSE to cancel the change
    "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

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Thanks.
    Is there any way i can gray it, and prevent it from receiving focus?

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    AFAIK you can only disable the whole LV.

    You could use the OWNERDRAW style and colour the background grey for the disable ones AND ignore any clicks on them.


    I would set the LPARAM to a code for the colour.

    Set the LV style to LVS_OWNERDRAWFIXED

    MFC
    add a handler for the OnDrawItem msg.

    WIN32
    handle the WM_DRAWITEM msg in the parents callback


    in both cases something like

    pDrawItem = (DRAWITEMSTRUCT *)lParam;

    Then in the handler
    Check lParam code (I would use an index to a COLORREF array)
    select and create correct colour brush (using my array element with the items lParam as the index)
    The DRAWITEM contains the info including a RECT and HDC, use FillRect()
    Kill Brush
    Draw text for item

    or

    create a loop for each col

    Use SetTextColor() if needed
    "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. Disabling a button
    By TheMajorRager in forum C# Programming
    Replies: 0
    Last Post: 10-14-2005, 05:09 PM
  2. disabling ALL keys?
    By elfjuice in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2005, 02:58 PM
  3. I need help disabling Keyboard and Mouse input on Edit controls
    By Templario in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2003, 11:59 PM
  4. Disabling beeps from return key
    By xds4lx in forum Windows Programming
    Replies: 4
    Last Post: 10-27-2002, 07:47 PM
  5. Disabling radio buttons
    By Bazz in forum Windows Programming
    Replies: 2
    Last Post: 08-28-2001, 06:29 PM

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