Results 1 to 14 of 14
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Unchecking Item in Listview

    Run it the old problem of listview instructions online not working in Access. I guess they're for some other platform.
    Have tried a zillion things but all go to error. Attempting to uncheck all rows except the one just checked



    Code:
    Private Sub ListView0_ItemCheck(ByVal Item As Object)     
    For i = 0 To ListView0.ListItems.Count - 1
                    If i <> Item.Index Then
                        Item(i).Check = False  <<<<<  How to correct this line ?
                    End If
          Next
    Thanks for any help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I created a listview control but cannot figure out how to allow 'checking' items. You could provide your db for analysis. Or least post code that loads the listview.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Certainly @June and thank you for trying. I have spent nearly all day on this and still not successful
    I initialise the listview thus
    Code:
    With ListView0
            .ListItems.Clear
            .ColumnHeaders.Clear
            .ColumnHeaders.Add , , , 300
            .ColumnHeaders.Add , , "Col2", 1000 '
            .ColumnHeaders.Add , , , 300
            .ColumnHeaders.Add , , "Col4", 7000
            .ColumnHeaders.Add , , "Col5", 2000
            .View = lvwReport
            .GridLines = True
            .FullRowSelect = True
            .Checkboxes = True
        End With
    And populate it with this (called for each new row)
    Code:
     With ListView0
                Set thelistview = .ListItems.Add
                thelistview.SubItems(1) = "111"
                thelistview.SubItems(2) = "222"
                thelistview.SubItems(3) = "333"
                thelistview.SubItems(4) = "444"
        End With
    Private Sub ListView0_ItemCheck(ByVal Item As Object) is the click event for a checkbox. is in here I want to clear any exiting checks, leaving only the current one.
    Private Sub ListView0_ItemClick(ByVal Item As Object) is the click event for the row.

    If any more needed, please ask.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want to allow only one item to be checked at a time? If so, why have checkboxes?

    There is no ItemCheck event in Properties window. I created this event procedure and used Debug.Print "test". It does not trigger since there is no event in properties for this procedure to associate with. I tried Updated event but nothing happens. I can get Enter event to trigger.

    ActiveX controls are known to be buggy in Access. Review https://answers.microsoft.com/en-us/...6-b80a10bb67c6

    Think I've done all I can.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try this. The form is loaded with no checkboxes checked. So, with this code, it's not possible to select more than one checkbox because as soon as you check a box, all the others are unchecked.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Dim MyView As MSComctlLib.ListView
    
    
    Private Sub Form_load()
        Dim i As Integer
        Set MyView = ListView0.Object
        With MyView
            .ColumnHeaders.Clear
            .ListItems.Clear
            .ColumnHeaders.Add , , , 300
            .ColumnHeaders.Add , , "Field2", 1000
            .ColumnHeaders.Add , , "Field3", 1000
            .ColumnHeaders.Add , , "Field4", 1000
            .View = lvwReport
            .GridLines = True
            .FullRowSelect = True
            .Checkboxes = True
        End With
        For i = 1 To 10
            MyView.ListItems.Add(i) = "F1 Test " & i
            MyView.ListItems.Item(i).ListSubItems.Add() = "F2 Test" & 1
            MyView.ListItems.Item(i).ListSubItems.Add() = "" 'show nothing in this column
            MyView.ListItems.Item(i).ListSubItems.Add() = "F4 Test" & 3
        Next i
    End Sub
    
    Private Sub ListView0_ItemCheck(ByVal Item As Object)
        Dim objItem As ListItem
        If Item.Checked = True Then
            Call ResetAllExcept(Item.Index)
        End If
    End Sub
    
    Private Sub ResetAllExcept(idx)
        Dim Item As Object
        For Each Item In MyView.ListItems
            If Item.Index <> idx Then
                Item.Checked = False
            End If
        Next
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Dave, did you test the ItemCheck event? Does it trigger? What purpose does Dim objItem As ListItem serve?

    I ran the sub from a button click by passing a literal number in place of Item.Index - the selective checking works.

    It appears Item.Index is not 0-based. I passed number 8 and the 8th record was left checked.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Yes. The code is post#5 works for me. The dim objItem is a leftover from the Edison approach (1000 different attempts). I selected the ItemCheck method from here:

    Click image for larger version. 

Name:	item1.png 
Views:	12 
Size:	35.7 KB 
ID:	49432

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    You've nailed it Dave, thanks very much. It works just as hoped
    @June thanks for that link. I haven't had that problem but I liked his comment Listviews look so much nicer than listboxs don't they!

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Again, if you only want one item selected at a time, why use checkboxes?

    Interesting, the event now works for me as well. I just copy/pasted your procedures. Weird could not get it to trigger before. Thinking maybe I was trying ItemClick instead of ItemCheck.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    It's a design preference June.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I added a line to increase font size. Checkbox remains same size. I avoid checkboxes (as well as radio buttons) because they require fine control to click on, can't change size. Whereas clicking anywhere on item row triggers ItemClick event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    And even smaller on a 4K screen. I know a click is just as good with full line select on but we've used checkboxes elsewhere and keeps things standard.
    Also our item click does something else. The listview control is greats esp with the col resize but it can be a pain to get some things working. I wish there were better info and less
    false leads on line where they tell you rubbish, at least as far as Access in concerned.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I did discover can select checkboxes with space bar and navigate list with up/down cursor keys. I can avoid mouse. I try to build forms to allow data entry without leaving keyboard.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I did discover can select checkboxes with space bar
    That's almost as old as me, and that's saying something. Up/down arrow keys and space bar work for a lot of lists. I can't recall if you can select several rows or non-contiguous rows with any ctrl key tricks or not.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Anyone used listview control in Access
    By Middlemarch in forum Forms
    Replies: 2
    Last Post: 12-27-2022, 01:26 AM
  2. Replies: 4
    Last Post: 06-02-2016, 08:13 AM
  3. Unchecking all check boxes on exit
    By Ayiramala in forum Access
    Replies: 3
    Last Post: 01-04-2015, 05:12 AM
  4. Replies: 6
    Last Post: 11-04-2012, 02:28 PM
  5. Filter listview
    By JJCHCK in forum Programming
    Replies: 2
    Last Post: 09-23-2011, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums