Listbox Selecting

  • Thread starter Thread starter JonWayn
  • Start date Start date
J

JonWayn

Setting the Selected property of a listbox puts a visual highlight on the
item indicated by the numeric argument to the selected property but the
ListIndex of the listbox doesnt reflect that that item is selected. What use
is the Selected property then? How can I programatically select an item in a
listbox and have the after_update event triggered as a result whereas the
listIndex property will reflect that item? Even using a statement like ;
lst1 = "SomeValue", doesnt seems to affect the value of the listbox. By the
way, the listbox I am working with here is unbound
 
If I recall, the AfterUpdate event may not trigger if you use code to modify
the selection.

On the other hand, there's no reason you couldn't add the following
where-ever you wished:

Call lstYourListBox_AfterUpdate

(using your listbox's name).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
You can, and I did, but the listbox's ListIndex property is not affected by
doing that. Other code that use the ListIndex property fail
 
If I understand what you are saying

lstMyListBox.Value = MyValue
lstMyListBox.Selected(lstMyListBox.ListIndex) = True

Ron W
 
The ListIndex property is read/only, you cannot directly set it. What I am
disappointed with is the fact that if you use the mouse to manually click,
say, the first item in a listbox, the listbox's ListIndex property (which is
0-based and given -1 when nothing is selected) gets set to 0, automatically.
However, when you try to similate that action in code by setting the
listbox's Selected property (as in lst1.Selected(0) = TRUE), or by setting
the Value property (as in lst1 = "Sam", or the equivalent, lst1.Value =
"Sam"), the visual effects will take effect ('Sam' is highlighted), but if
you were to read the ListIndex property, it remains -1 as if nothing was
selected. I have found workarounds but it is still ridiculous that for many
versions of Access this behaviour persists.
 
well, forget my last reply. Looking thru the examples in ListIndex help, the
ListIndex property can directly be set. Dunno why the help states that it is
read/only though
 
Thats correct. After years of being frustrated about this feature, I just
now realize that using SetFocus just before setting ListIndex allows direct
access to ListIndex. Not only is that undocumented, it is also misleading to
describe the property as read/only
 
Back
Top