473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ 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 2576
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.ListCoun t - 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
2389
by: Supra | last post by:
in vb6 listbox1.remove item 5 how will i do in vb.net? regards
0
1373
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 item and executing the following code from a button click event: lstBoxs.Items.Remove(lstBox.SelectedItem);
4
6186
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) listBox1.Items.Remove(filename); } gives me the error :
4
18294
by: mostafa atalla | last post by:
How can I remove some selected items from the listBox in the run time ??
1
2774
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 editing bit is not a problem, but I can't get the selected item to resize, as the listbox does for the "Add/Remove programs". The initial thought I had was to have a handler for the MeasureItem event, then have the condition of whether the...
4
11500
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 select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at multiple examples and they all do it this way. What's wrong? (variables are also being set to the values...
1
5882
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 sql server table during page load time and the second one is empty, now i want if a user select item/s in first listbox then it should add in another listbox after clicking add withour postback using javascript and the item's text which is...
3
6052
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. senderBox.Items.RemoveAt(senderbox.selectedIndex) I was told that I need to copy selecteditems to an array and run the For each routine from the array instead. Can someone please give me some idea on how to accomplish this? Thanks a million.
3
5754
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 selecting an item. I tried the following code but it displays the test message whether they're selecting or unselecting: For intRow = 1 To Me.lstEmployees.ListCount - 1 If Me.lstEmployees.Selected(intRow) = False Then MsgBox "Previously...
1
1479
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. Things I have tried: When i place a loop for the selected items and use listbox1.requery (For requery the listbox) the second selected item is being unselected. Is there any way i can remember the selected list index. Pls let me know Thanks...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
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 we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.