Results 1 to 5 of 5

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

  1. #1

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

    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
    5,647

    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.
    Last edited by fafalone; Nov 24th, 2020 at 09:45 PM.

  3. #3

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

    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
    472

    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

  5. #5
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Re: Enable/disable entries in listview controls

    Friends,

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

    First Column is Check Box.

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

    In next time loading, the checked row is showing as checked. But I don't want to deselect and the specific row need to be disabled (protect from unselect)

    How can i do that? please guide me.

    Thanks.



    Quote Originally Posted by Bezzie View Post
    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