Log in

View Full Version : [SOLVED:] Grid Control Rows Not Displaying Selected State Correctly



johnywhy
03-02-2014, 02:21 PM
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!

johnywhy
03-02-2014, 03:19 PM
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!

HiTechCoach
03-03-2014, 09:58 AM
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 (http://www.excelguru.ca/content.php?184)

johnywhy
03-03-2014, 10:05 PM
fwiw, here's a stripped-down access db, containing only the objects and code necessary to duplicate the issue.


https://drive.google.com/folderview?id=0B8FhwalyGcnvNWVMTWdvd1FaMEk


let me know if you cannot open this.


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

johnywhy
03-04-2014, 04:32 AM
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/0B8FhwalyGcnvQlh4SDcyUk11bWc

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

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/0B8FhwalyGcnvT3FucTZ0Qm15ekE

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!

johnywhy
04-21-2014, 09:22 AM
Hi, NB, this thread concerns LISTBOXES NOT GRIDS.