473,385 Members | 1,712 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,385 software developers and data experts.

Removing items from a listbox and from object collection

maylortaylor
72 64KB
I am having troubles with my listbox. I have two buttons for the box.

1)add files
2)remove files

..simple enough. However, whenever i use the remove button it will take the text out of the listbox; but it will not remove it from the selectobjectcollection (i'm assuming that's where the info is stored..sorta new to VB)

The end of the program takes all the files in the list box and compiles them into a XML file. However, at the present moment the program adds every file I initially added using the "add files" button. So, basically, the "remove file" button is only for physical appearences on the list box..nothing more.

Any help?

This is the code for the "Remove Files" button.

Expand|Select|Wrap|Line Numbers
  1.         Do While (listbox.SelectedItems.Count > 0)
  2.             listbox.Items.Remove(listbox.SelectedItem)
  3.         Loop
  4.  
Nov 20 '12 #1
6 2241
Flinty
11
There is no such property as "SelectedItems" or "SelectedItem" so the code will never work. I do not understand why you are not getting error messages when you try to run this code. Look in the MSDN Library and search for listbox and look for RemoveItem method.
Further the "Selected" property is a boolean property and is either True or False only.
Feb 2 '13 #2
zmbd
5,501 Expert Mod 4TB
@maylortaylor:
You did not mention the version information for the environment; hence you might get a verity of answers. You should reference this: ListBox Control for Visual Basic 6.0 Users.
Second, you should always attempt to compile your code before posting. Most VBE will provide you with some information.

@Flinty:
You should also reference the link I have given above. You will find that your statements are not the most correct as related to the properties. In fact, quoted from the table provided in the the link given:
Visual Basic 6.0 = SelCount
Visual Basic 2005 Equivalent = Count (SelectedItem.Count)
I've altered the quote slightly to allow for the correct table header relationships.
Feb 3 '13 #3
Flinty
11
As the question was posted under Visual Basic 4/5/6 it's reasonable to use the properties and methods relating to these versions and not VB.Net.
Feb 3 '13 #4
zmbd
5,501 Expert Mod 4TB
and you'll note the link is to the VB6 {cross-reference}
As a Chemist and a Mod I am very aware of what little differences in titles and names can mean.
I do not usually provide links or suggestions without due thought, proof reading, and other considerations.
Feb 3 '13 #5
Flinty
11
Firstly I recognise your expertise and high position and I do not wish to cause any upset, but your link is for Visual Studio 5 (.Net)users and how it differs from VB 6.0
Feb 3 '13 #6
zmbd
5,501 Expert Mod 4TB
I understand what you are saying.

First, I never assume that a poster will be in the correct forum. All too often questions for VBA shows up in JAVA and MS Access in one of the other DB forums. To that extent, you will note that I have lightly "admonished" OP for failing to note which version of the BASIC language is being used.

Take a careful look at the code offered by OP... does it not strike you that the formatting is the same as would be seen from code that is from intellisense - such as from VS2005? It would also explain why OP is not seeing an error, it also explains the other behavior OP is observing (well, to a point).
Code taken directly from VS2005:
Expand|Select|Wrap|Line Numbers
  1. ' Visual Basic 2005
  2. Dim theItem As ListViewItem
  3. If ListView1.SelectedItems.Count > 0 Then
  4.     theItem = ListView1.SelectedItems(0)
  5. Else
  6.     theItem = Nothing
  7. End If
You will also want to take note that OP could very well be using an ActiveX control... I'll stay within the VB6 editor reference: Visual Studio 6.0 - SelectedItem Property (ActiveX Controls)

Thus, without knowing the correct IDE that OP is using, I reviewed the information at hand along with what experience I have in programing and selected an answer that could cover either a VB6 or earlier question or one that is possibly a dot-net starting with VS2005....

-
As for causing upset... it takes considerably more than a slight disagreement to upset me (well, provided I get a few hours of sleep :) )
Despite my age and knowledge; I am wise enough to understand that I do make mistakes.
Feb 3 '13 #7

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

Similar topics

2
by: Jim M | last post by:
I am having trouble changing any properties of the web form listbox from client side javascript. As an example, all of the lines below seem to cause an error... temp =...
4
by: Robert | last post by:
Hi I have an Form1 class generated with studio with an listbox on it. how can i access this listbox from other classes ? public class Form1 : System.Windows.Forms.Form { public...
3
by: Filippo P. | last post by:
Hi there, I have a menu (Collection) that needs to be trimmed based on security access of the logged user. protected void AdjustMenuBasedOnUserSecurity(Items ItemsList) { foreach (Item i in...
2
by: Erik | last post by:
Hi All, If I add an object to a hashtable for instance, then further down the line I remove it, do I have to set it to null first before I remove it or does removing it from the collection...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
3
by: papa smerf | last post by:
'Here is some of the code I have so far. Dim Contacts(25, 4) As String This is where I add to the listbox Private Sub btnAddToList_Click(ByVal sender As System.Object, ByVal e As...
0
by: Mike | last post by:
Hi, I have a collection object bound to a data grid, after I remove an item from the collection, the minute I click on the datagrid I get an error saying the specified argument was out of the...
2
by: Wisher | last post by:
I can't update a listbox from other class with it's own thread. My code: The main class: <....> public partial class mainForm : Form { <....> private delegate void...
0
by: vivek kapile | last post by:
Title: Javascript for Adding & Removing Items from a one Listbox to another Author: Vivek Kapile Email: snipped Language: JavaScript Platform: Javascript in ASP.net...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.