Listbox click event

  • Thread starter Thread starter mscertified
  • Start date Start date
M

mscertified

In a multi-select (simple) listbox, how do I get the row selected, and how do
I know if it's an initial select or a re-select (i.e. clicking on an already
selected item this unselecting it?) Thanks.
 
mscertified said:
In a multi-select (simple) listbox, how do I get the row selected, and how
do
I know if it's an initial select or a re-select (i.e. clicking on an
already
selected item this unselecting it?) Thanks.

Some untested air code:

Dim itm As Long

With Me.List0
For Each itm In .ItemsSelected
If itm = .ListIndex Then
Debug.Print .ItemData(.ListIndex) & " selected"
Else
Debug.Print .ItemData(.ListIndex) & " de-selected"
End If
Next
End With

This isn't a perfect solution, but if you take careful note of what's
happening in the debug window as you click around, you'll see that it's
workable.
 
I don't believe there's any way, other than keeping track of all of the
selected rows yourself.
 
Stuart McCall said:
Some untested air code:

Dim itm As Long

With Me.List0
For Each itm In .ItemsSelected
If itm = .ListIndex Then
Debug.Print .ItemData(.ListIndex) & " selected"
Else
Debug.Print .ItemData(.ListIndex) & " de-selected"
End If
Next
End With

This isn't a perfect solution, but if you take careful note of what's
happening in the debug window as you click around, you'll see that it's
workable.

Correction:

Dim itm As Variant
 
The following worked for me. I created a multi-select (simple) listbox, and
added two textboxes to a form. Then used the following to identify the value
in the bound column of the most recently selected item in the listbox, and to
also determine whether it was selected

Private sub lst_Attributes_Click

Me.txt_Last_Item_Clicked = Me.lst_Attributes.Column(0)
Me.txt_IsSelected =
Me.lst_Attributes.Selected(Me.lst_Attributes.ListIndex)

end sub

HTH
Dale
 
Back
Top