Problem with Multi-Select List Boxes

  • Thread starter Thread starter Neil Ginsberg
  • Start date Start date
N

Neil Ginsberg

I'm having a problem with a multi-select list box set to Simple
multi-selection. If multiple items are selected and then I change the items
in the list, the list positions previously selected are still selected. For
example, if the list contains a, b, c, d, and e, and b and c are selected,
and then the list is changed to contain v, w, x, y, z, the w and x items are
selected.

This doesn't happen every time; only intermittently. Even though the items
should be cleared when the rowsource is changed, I added code to explicitly
clear every item and to perform a repaint when the rowsource changes, but it
had no effect.

This clearly must be a glitch in Access. Anyone familiar with it?

Thanks,

Neil
 
Hi Neil

The selected items are maintained as indexes into the list, rather than item
values, so if your change the rowsource I would expect that the items at the
same positions would remain selected.

You say that you "explicitly clear each item", but perhaps that code is not
working properly.

The following should work:

Var vItem as Variant
With YourListbox
For Each vItem in .ItemSelected
.Selected(vItem) = False
Next vItem
End With

You should do this *before* changing the RowSource.

There should be no need to Requery or Repaint.
 
Thanks for the note. I found that changing the rowsource actually did clear
the list; but I added the code to explicitly clear the list anyway. In
anycase, I'll try your tip of clearing the list first, before changing the
rowsource and see what happens. Thanks.

Neil


Graham Mandeno said:
Hi Neil

The selected items are maintained as indexes into the list, rather than item
values, so if your change the rowsource I would expect that the items at the
same positions would remain selected.

You say that you "explicitly clear each item", but perhaps that code is not
working properly.

The following should work:

Var vItem as Variant
With YourListbox
For Each vItem in .ItemSelected
.Selected(vItem) = False
Next vItem
End With

You should do this *before* changing the RowSource.

There should be no need to Requery or Repaint.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Neil Ginsberg said:
I'm having a problem with a multi-select list box set to Simple
multi-selection. If multiple items are selected and then I change the items
in the list, the list positions previously selected are still selected. For
example, if the list contains a, b, c, d, and e, and b and c are selected,
and then the list is changed to contain v, w, x, y, z, the w and x items are
selected.

This doesn't happen every time; only intermittently. Even though the items
should be cleared when the rowsource is changed, I added code to explicitly
clear every item and to perform a repaint when the rowsource changes,
but
it
had no effect.

This clearly must be a glitch in Access. Anyone familiar with it?

Thanks,

Neil
 
Back
Top