473,471 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Remove Unselected Items from listbox

14 New Member
Hi,
I need a code to remove all the items that are unselected from a listbox.
I really need this!!
Thanks!!
Jan 19 '10 #1
3 2521
vb5prgrmr
305 Recognized Expert Contributor
You will need to loop through the list box from listcount - 1 to 0 step -1 and check the selected property and if not selected use the remove method.



Good Luck
Jan 19 '10 #2
esperanto234
14 New Member
Thank you very much, I already did it.

In case someone wants to know, the answer is the following:

If NOM <> "" Then
Dim ix As Integer
Dim bFound As Boolean

For ix = 0 To ctlCHN.ListCount - 1
If ctlCHN.List(ix) = NOM.Text Then
bFound = True
Exit For
End If
Next

If bFound = False Then
ctlCHN.AddItem NOM.Text
End If
End If
Jan 19 '10 #3
smartchap
236 New Member
Dear esparanto234 I think the question asked by u & code posted by u are not same. In ur code actually u are checking whether textbox entry already exists in the listbox or not, if not then it is added to the listbox. Deletion is no where done in ur code. To delete the unselected items, u need to loop through index=0 to index=Listcount-1 and check if a particular index item is selected or not. If it not selected then delete it (but adjust loop accordingly as now listbox has 1 item less than previous). So through loop u can delete unselected item(s).
Jan 28 '10 #4

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

Similar topics

4
by: Supra | last post by:
in vb6 listbox1.remove item 5 how will i do in vb.net? regards
0
by: Shawn K | last post by:
I populate a listbox with the following code when my form loads: lstBox.Items.Add("value"); Once the page loads, I give the user the ability to remove items from the list box by selecting an...
4
by: Bilo | last post by:
I dont know what i am doing false. the code : private void button2_Click(object sender, System.EventArgs e) { foreach (string filename in listBox1.SelectedItems)...
4
by: mostafa atalla | last post by:
How can I remove some selected items from the listBox in the run time ??
1
by: Dan Bass | last post by:
I'm looking to develop a listbox with in-place editing where as each item is selected, it grows to fit in all the text boxes. When the item is deselected, it shrinks back to its original size. The...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
1
by: deepak | last post by:
hi , i have 2 listbox and 2 buttons like add and remove, both listbox have multiple selection true so that i can either add or remove multiple selected items. the first listbox is populated with...
3
by: Bill Nguyen | last post by:
I use the following example (from another post) and it seemed to work fine. However, when I add the syntax to remove the selected item from the senderbox, I got error....
3
by: manning_news | last post by:
Using 2003. How do I tell if a selected item on a multi-select listbox is now unselected? If a user unselects an item, I want to prompt them that they've unselected it. No prompt if they're...
1
by: bairamsunil | last post by:
I have a list box in which items are selected alternately, depending on the selection I have to remove the records in another table which matches this item as well as i have to refresh the list box....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.