473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

List Box Counter of Items Selected

Hello Everyone,

I am trying to keep a running total of the number of items selected in a multiselect list box. I want to do this in vb code and update the number dynamically everytime they select or deselect an item in the list. This number will be displayed in a textbox or a label on a form so the user knows how many things they have selected at any time.

Is this possible?

Thanks to everyone!
Jul 19 '07 #1
3 6328
Hello Everyone,

I am trying to keep a running total of the number of items selected in a multiselect list box. I want to do this in vb code and update the number dynamically everytime they select or deselect an item in the list. This number will be displayed in a textbox or a label on a form so the user knows how many things they have selected at any time.

Is this possible?

Thanks to everyone!
Hi Schmidt
Yep its dead easy try this

[code]

Private Sub List0_AfterUpdate()

For loop1 = 0 To Me.List0.ListCount
If Me.List0.Selected(loop1) = True Then vCounter = vCounter + 1
Next loop1

Me.Text2 = vCounter


End Sub

List0 is my list box, Text2 is the name of my text box.
You can also use this function by changing the If statement to:

Me.List0.Selected(loop1) = True

If you add this as an After update subroutine to a check box it will select all the rows in your list box (False = Unselect).

Daz
Jul 19 '07 #2
ADezii
8,834 Expert 8TB
Hello Everyone,

I am trying to keep a running total of the number of items selected in a multiselect list box. I want to do this in vb code and update the number dynamically everytime they select or deselect an item in the list. This number will be displayed in a textbox or a label on a form so the user knows how many things they have selected at any time.

Is this possible?

Thanks to everyone!
It is very possible and here is how it is done:
  1. ASUMPTIONS
    1. List Box Name: lstTest.
    2. Text Box Name to write the Number of Selected Items to: txtNoOfItemsSelected.
  2. Copy and Paste the following code to the AfterUpdate() Event of lstTest
    Expand|Select|Wrap|Line Numbers
    1. Private Sub lstTest_AfterUpdate()
    2. Dim ctlSource As Control, intCurrentRow As Integer
    3. Dim intNoSelected As Integer
    4.  
    5. Set ctlSource = Me!lstTest
    6.  
    7. For intCurrentRow = 0 To ctlSource.ListCount - 1
    8.   If ctlSource.Selected(intCurrentRow) Then
    9.     intNoSelected = intNoSelected + 1
    10.   End If
    11. Next intCurrentRow
    12.  
    13. Me!txtNoOfItemsSelected = "You have selected " & intNoSelected & " Items!"
    14. End Sub
Jul 19 '07 #3
Thanks for the help. It works beautifully!
Jul 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
2
by: Neil Ginsberg | last post by:
I'm having a problem with a multi-select list box set to Simple multi-selection. If multiple items are selected and then I change the items in the list, the list positions previously selected are...
3
by: rohith | last post by:
Hope someone can help with this. I am trying to add items to a drop down list from a database. I can do this fine by using the bind method. What I want to do also is to set the selected item to...
2
by: Peter | last post by:
Hello! Please, could anyone tell, is it possible to set multiple items to be selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
8
by: malkarouri | last post by:
Hi everyone, I have an algorithm in which I need to use a loop over a queue on which I push values within the loop, sort of: while not(q.empty()): x = q.get() #process x to get zero or more...
1
by: raam | last post by:
hi I have a list box with some country names from database. when i click search button the "country" list selecteditem should be selected. but it is not. here is my code where iam using a...
5
Claus Mygind
by: Claus Mygind | last post by:
I have a list box and want to limit the user to selecting a max of 5 items from the list. I've put in a counter which warns the user that more than 5 items have been selected, however I cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.