ListBox and AfterUpdate Event

H

Hajo

Hello,

I'm wondering why I've no success in reading out selected ListBox rows in
the function of AfterUpdate Event of the ListBox:

Private Sub lstTestListBox_AfterUpdate()
If lstTestListBox.ItemsSelected.Count > 0 Then
Debug.print "Something selected"
End If
End Sub

I assume that after selecting a row in the ListBox the AfterUpdate event
will get triggered. But no selection is "counted", even though one row is
definitely selected. And indeed, lstTestListBox.ItemsSelected.Count is one
if I read it out of another function. But it doesn't work with AfterUpdate.

Why?

Thank you,
Hajo
 
D

Dirk Goldgar

Hajo said:
Hello,

I'm wondering why I've no success in reading out selected ListBox rows in
the function of AfterUpdate Event of the ListBox:

Private Sub lstTestListBox_AfterUpdate()
If lstTestListBox.ItemsSelected.Count > 0 Then
Debug.print "Something selected"
End If
End Sub

I assume that after selecting a row in the ListBox the AfterUpdate event
will get triggered. But no selection is "counted", even though one row is
definitely selected. And indeed, lstTestListBox.ItemsSelected.Count is
one
if I read it out of another function. But it doesn't work with
AfterUpdate.

Why?


The ItemsSelected collection is only filled when the list box is in one of
the Multiselect modes (Simple or Extended). If you list box is in the
default, single-select mode (its MultiSelect property is set to None), then
ItemsSelected will always return an empty collection.

For a single-select list box, just test whether the list box's Value is Null
or not, using the IsNull function. But with a single-select list box, I
don't think the AfterUpdate event can fire unless the user clicked and thus
selected something, so the point seems to be moot. Single-select list boxes
don't support "de-selecting".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top