Consulting

Results 1 to 6 of 6

Thread: Grid Control Rows Not Displaying Selected State Correctly

  1. #1

    Grid Control Rows Not Displaying Selected State Correctly

    this is very weird (and urgent).

    when i select rows in a grid control on a form, using access vba, some rows behave exactly the opposite of how they're supposed to behave-- they APPEAR unselected when i select them, and selected when i unselect them. However, when i check their Selected property with VBA they return the expected value.

    video:
    youtu.be/Ae0adXdmT48

    i repeatedly requery the listbox while the form it's on is hidden (MyForm.Visible=False). It seems that the more times i requery, the worse the problem gets.

       
     ' requery
        oListBox.Requery
    Then i select ALL items in the list box by looping through them.

    Sub Select_AllListItems(oListBox As ListBox)
    ' select all items in list
        DoCmd.Echo False
        oListBox.Visible = False
    
        Dim lngRow As Long
        For lngRow = 0 To oListBox.ListCount - 1
            oListBox.Selected(lngRow) = True
        Next
    
        ' jump to top
        oListBox.Selected(0) = True
    
        DoCmd.Echo True
        oListBox.Visible = True
    End Sub
    This problem seems unrelated to the number of times i run the above procedure. It seems only related to multiple requeries. At first, it does not happen. Then with repeated requeries (while the form is hidden), the problem gets progressively worse.

    maybe i'm accessing the form in the wrong way, creating multiple instances or something. But i'm not using the "Form_" syntax anyplace.

    also, this listbox query contains a vba function which is in the code-behind of another form.

    help!

    note, i may post this question on other MS Access forums, so plz only answer in one place. thx!
    Last edited by johnywhy; 03-02-2014 at 02:36 PM.

  2. #2
    update, i trimmed my code, so i'm doing the requery on the listbox much less frequently, and only when the form is visible. Still getting this crazy behavior!
    Last edited by johnywhy; 03-02-2014 at 03:30 PM.

  3. #3
    Quote Originally Posted by johnywhy View Post
    note, i may post this question on other MS Access forums, so plz only answer in one place. thx!
    Then only ask in on place.

    FWIW: How cross posting is often viewed: Since this is posted in multiples place I will just wait to answer. No need to duplicate any efforts.

    See: A message to forum cross posters
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  4. #4
    fwiw, here's a stripped-down access db, containing only the objects and code necessary to duplicate the issue.


    https://drive.google.com/folderview?...WVMTWdvd1FaMEk


    let me know if you cannot open this.


    i think it might be a problem with my display driver.

  5. #5

    Possibly Solved. Possible Microsoft Access Bug.

    i think i solved this.

    Problem: when VBA selects all rows in a listbox every time the listbox is requeried, selection behavior gets wonky: some selected rows do not appear selected.

    Demo of problem:
    https://drive.google.com/file/d/0B8F...lh4SDcyUk11bWc

    instructions:
    https://docs.google.com/document/d/1...avxFRMocvOZ1RY

    the fix is to UNselect all rows in the target table before requerying it.

    Produced wonky selection behavior:
    1. ListBox Where condition changes
    2. Requery ListBox
    3. Select All ListBox Rows
    4. Repeat

    Fixed wonky selection behavior:
    1. ListBox Where condition changes
    2. UNselect All ListBox Rows
    3. Requery ListBox
    4. Select All ListBox Rows
    5. Repeat

    see debug-fix
    https://drive.google.com/file/d/0B8F...3FucTZ0Qm15ekE

    i think this might be a Microsoft Access Bug, because the behavior (selected rows appearing unselected) is abnormal.

    i'll mark this thread solved, after anybody confirms my fix works.

    thx!

  6. #6
    Hi, NB, this thread concerns LISTBOXES NOT GRIDS.

Tags for this Thread

Posting Permissions

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