Multi listbox change event - selected or deselected

  • Thread starter Thread starter kalle
  • Start date Start date
K

kalle

Good day Group,

Need some guidance how to determine if the click on a multi listbox
is
a selection or a deselection. I am building an array by the
multi listbox like (in listbox change event):

arJoin(UBound(arJoin)) = Me.ListBox1.Column(1, Me.ListBox1.ListIndex)

If the click is a selection then OK but if it is a deselection I need
to know and
take care of that in some way.

Grateful for some hints.

Brgds

CG Rosén
 
hi,

Code:
Dim x As Integer

Private Sub ListBox1_Change()
Dim i As Integer, n As Integer

For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then n = n + 1
Next i

If n > x Then
x = x + 1
MsgBox "select"
Else
x = x - 1
MsgBox "deselect"
End If

End Sub
 
I forgot to tell you that the solution given before is ok if the MultiSelect property = fmMultiSelectMulti
 
I forgot to tell you that the solution given before is ok if the MultiSelect property = fmMultiSelectMulti

--
isabelle

Le 2011-04-23 23:48, isabelle a écrit :


Code:
Dim x As Integer[/QUOTE]
[QUOTE]
Private Sub ListBox1_Change()
Dim i As Integer, n As Integer[/QUOTE]
[QUOTE]
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then n = n + 1
Next i[/QUOTE]
[QUOTE]
If n > x Then
x = x + 1
MsgBox "select"
Else
x = x - 1
MsgBox "deselect"
End If[/QUOTE]
[QUOTE]
End Sub
- Dölj citerad text -

- Visa citerad text -

Hi Isabelle,

Thanks for your code. I have problems to figure it out. Seemes to work
för the
last selected item in the list but not if there are several selections
and one is
deselected. Is not the value for x set at all?

Brgds

CG Rosén
 
I forgot to tell you that the solution given before is ok if the MultiSelect property = fmMultiSelectMulti

--
isabelle

Le 2011-04-23 23:48, isabelle a écrit :


Code:
Dim x As Integer[/QUOTE]
[QUOTE]
Private Sub ListBox1_Change()
Dim i As Integer, n As Integer[/QUOTE]
[QUOTE]
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then n = n + 1
Next i[/QUOTE]
[QUOTE]
If n>  x Then
x = x + 1
MsgBox "select"
Else
x = x - 1
MsgBox "deselect"
End If[/QUOTE]
[QUOTE]
End Sub
- Dölj citerad text -

- Visa citerad text -

Hi Isabelle,

Thanks for your code. I have problems to figure it out. Seemes to work
för the
last selected item in the list but not if there are several selections
and one is
deselected. Is not the value for x set at all?

Brgds

CG Rosén

Would it work to keep the total number of selected items in a static
variable, and then you just count the selected items and compare it to
the previous total in each click event, then update the total to the
current number?
 
kalle laid this down on his screen :
Hi Isabelle,

Thanks for your code. I have problems to figure it out. Seemes to work
för the
last selected item in the list but not if there are several selections
and one is
deselected. Is not the value for x set at all?

Brgds

CG Rosén

Is this the same project ("Array - delete and replace elements" posted
4/17/2011) for building strings that you said you'd work towards
following my suggestions?

Do you want some help with implementing my suggestion? Or do you still
want to keep messing around trying to figure out how to get this
approach working?
 
yes you're right and then just replace the "MsgBox..." by run another code in case is "select" or "deselect"

--
isabelle

Le 2011-04-24 03:52, mscir a écrit :
Would it work to keep the total number of selected items in a static variable,
 
Back
Top