Results 1 to 4 of 4

Thread: [RESOLVED] Enable/disable entries in listview controls

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    414

    Resolved [RESOLVED] Enable/disable entries in listview controls

    I have two ListView controls with checkboxes enabled. Both ListViews have the same entries. The one ListView is for entries that must be included and the second ListView is for entries that must be excluded.

    How can I disable/enable an entry in one ListView when the equivalent entry in the other ListView is selected/deselected?

    Say, for instance, both ListViews contain the words Red, Blue, Green, Black.

    When the user select the checkbox next to Red in the first ListView the entry for Red in the second ListView must be disabled so that Red can't be selected in the second ListView. And when the checkbox next to red is deselected in the first ListView then the Red entry in the second ListView must be enabled again so that it is available for selection again if needed.

    Is this possible?

    PS. It must work both ways.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,624

    Re: Enable/disable entries in listview controls

    Are you using the 'Microsoft Windows Common Controls 5.0' or 'Microsoft Windows Common Controls 6.0'?

    If you're using 6.0 it has a built-in event for when an item is checked, so it's very easy to set:
    Code:
    Private Sub ListView2_ItemCheck(ByVal Item As LvwListItem, ByVal Checked As Boolean)
    If (Item.Index = [indexofRed]) And (ListView1.ListItems([indexofRed]).Checked = True) Then
        If Checked = True Then
            Item.Checked = False
        End If
    End If
    End Sub
    You'd put the same kind of thing in the event for ListView1_ItemCheck to make it work both ways.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    414

    Re: Enable/disable entries in listview controls

    Thanks. I was thinking of disabling the listitem in the other listview but just unselecting it there also works. Always over complicating things

    Just one question. Is there a way to hide the ugly blue selection of the list items?

    When user select/deselect the checkboxes in the listview the first item gets highlighted and stays highlighted as other checkboxes in the listview are selected/deselected. Or when user clicks on the list items the selected list item gets highlighted and stays highlighted until another item are clicked, which are then highlighted, or the listview loses focus.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    414

    Re: Enable/disable entries in listview controls

    Thanks for pointing me in the right direction.

    Got it working. At least the ugly highlight jumps around with the selections as they are made
    Code:
    Private Sub lvwInclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
        lvwInclude.ListItems(Item.Index).Selected = True
    
        If lvwInclude.ListItems(Item.Index).Checked = True Then
            lvwExclude.ListItems(Item.Index).Checked = False
            lvwExclude.ListItems(Item.Index).Selected = True
        End If
    End Sub
    
    Private Sub lvwInclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
        lvwInclude.ListItems(Item.Index).Checked = Not lvwInclude.ListItems(Item.Index).Checked
        lvwInclude_ItemCheck Item
    End Sub
    
    Private Sub lvwExclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
        lvwExclude.ListItems(Item.Index).Checked = Not lvwExclude.ListItems(Item.Index).Checked
        lvwExclude_ItemCheck Item
    End Sub
    
    Private Sub lvwExclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
        lvwExclude.ListItems(Item.Index).Selected = True
        
        If lvwExclude.ListItems(Item.Index).Checked = True Then
            lvwInclude.ListItems(Item.Index).Checked = False
            lvwExclude.ListItems(Item.Index).Selected = True
        End If
    End Sub

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