CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010

    Disable the Check Box in List View Control


    I am having a listview and I have loaded all the DB values.

    First Column is Check Box.

    If i checked and click the button, the calculation will be made and values will be stored in DB including the checked value too.

    In next time loading, the checked check box need to be shown as checked (I am using the following code).

                            If (.Fields("LPrint") = True) Then
                                ListView1.ListItems(k).Checked = True
                                ListView1.ListItems(k).Checked = False
                            End If
    But I don't want to deselect and the specific checkbox after loading which need to be disabled (protect from unselect). I have tried following code but not working.

    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
        If ListView1.ListItems(Item.Index).Checked = True Then ListView1.ListItems(Item.Index).Selected = False
    End Sub

    Please guide me.


  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Disable the Check Box in List View Control

    You have to handle the LVN_ITEMCHANGING notification, then
    • check (for the list control item which checkbox you want to disable) the LVIS_STATEIMAGEMASK item state (
    • if it was set then use the LVIS_STATEIMAGEMASK mask to isolate the one-based index of the state image (see
    • if this "state image" was set then your notification message handler has to return TRUE to prevent changes

    Sorry if my description would be not 100% correct! I implemened such handling about two decades back in C++/MFC project.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width