ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multi listbox change event - selected or deselected (https://www.excelbanter.com/excel-programming/444483-multi-listbox-change-event-selected-deselected.html)

kalle

Multi listbox change event - selected or deselected
 
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

isabelle

Multi listbox change event - selected or deselected
 
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


--
isabelle

Le 2011-04-23 05:02, kalle a écrit :
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


isabelle

Multi listbox change event - selected or deselected
 
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 :
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




kalle

Multi listbox change event - selected or deselected
 
On 24 Apr, 06:12, isabelle wrote:
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 :



hi,


Code:

Dim x As Integer
Code:


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

- 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

mscir

Multi listbox change event - selected or deselected
 
On 04/24/2011 12:34 AM, kalle wrote:
On 24 Apr, 06:12, wrote:
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 :



hi,


Code:

Dim x As Integer
Code:


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

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


GS[_2_]

Multi listbox change event - selected or deselected
 
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?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc



isabelle

Multi listbox change event - selected or deselected
 
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,


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?




All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com