Multi listbox change event - selected or deselected

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
 
I

isabelle

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

isabelle

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

kalle

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
 
M

mscir

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?
 
G

GS

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?
 
I

isabelle

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,
 

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