472,980 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Remove element from array list and combobox......

Don
My user control has a combobox with an arraylist attached to it along with custom add and remove methods.

The "Add" method is working great. However I don't understand why the "Remove" method isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do.

A couple of notes: cbx is the name of the combobox within my usercontrol, file is the name of the arraylist within my usercontrol. To try and debug this issue, I added a public variable elsewhere in my usercontrol. This variable is named "test". When I "watch" this test variable as the remove method operates, it DOES get set to 0 which IS the element that needs to be removed. File.count AND cbx.count both equal 3.

Thanks for any assistance you may be able to provide.

--

Don

'This is the call to the add method that DOES work.
cbxMyComboBox.add("New Item")

'This is the add method that DOES work
Public Overridable Sub add(ByVal n As String)
'add item to the combobox
cbx.Items.Add(n)
File.Add(n)
noLocations = false
'select the new item in the combobox
If Not cbx.Items.Count = 0 Then
cbx.SelectedIndex = cbx.Items.Count - 1
End If
end sub

'This is the call the remove method that DOESN'T work
cbxMyControl.Remove(cbxMyControl.selectedindex)

'This is the Remove method that DOESN'T work.
Public Overridable Sub remove(ByVal i As Integer)
cbx.Items.Remove(i)
File.Remove(i)
Test = i
If Not cbx.Items.Count = 0 Then
cbx.SelectedIndex = 0
noLocations = False
Else
noLocations = True
End If
end sub

Nov 20 '05 #1
3 3743
Cor
Hi Don,

Did you know that you did use remove with the syntax from removeat?

Cor
Nov 20 '05 #2
* "Don" <No****@nothanks.com> scripsit:
The "Add" method is working great.* However I don't understand why the "Remove" method isn't working.* It
neither removes the item from the arraylist nor from the combobox like it's supposed to do.

A couple of notes:* cbx is the name of the combobox within my usercontrol, file is the name of the arraylist
within my usercontrol.* To try and debug this issue, I added a public variable elsewhere in my usercontrol.*
This variable is named "test".* When I "watch" this test variable as the remove method operates, it DOES get set
to 0 which IS the element that needs to be removed.* File.count AND cbx.count both*equal 3.


You will have to pass a reference to the object you want to be removed
to the 'Remove' method, the index can be passed to the 'RemoveAt'
method, not to 'Remove'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Hello Don,

the Remove method expects you to pass in the object to be removed. For your
example below, that would be the string "New Item", not the index of the
element to remove. If you want to remove an item at a specific index, you
can use the RemoveAt method instead.

HTH

Antoine
Microsoft Visual Basic .NET
--
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Don" <No****@nothanks.com>
Subject: Remove element from array list and combobox......
Date: Sun, 14 Dec 2003 11:16:41 -0500
Lines: 183
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_00B3_01C3C233.BFCD9DB0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <Oi**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: pcp05997552pcs.benslm01.pa.comcast.net 68.81.60.128
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP09.
phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:163977
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

My user control has a combobox with an arraylist attached to it along with custom add and remove methods.The "Add" method is working great. However I don't understand why the "Remove" method isn't working. It neither removes the item from the
arraylist nor from the combobox like it's supposed to do.A couple of notes: cbx is the name of the combobox within my usercontrol, file is the name of the arraylist within my usercontrol. To try and debug
this issue, I added a public variable elsewhere in my usercontrol. This
variable is named "test". When I "watch" this test variable as the remove
method operates, it DOES get set to 0 which IS the element that needs to be
removed. File.count AND cbx.count both equal 3.Thanks for any assistance you may be able to provide.
--
Don
'This is the call to the add method that DOES work.
cbxMyComboBox.add("New Item")
'This is the add method that DOES work
Public Overridable Sub add(ByVal n As String)
'add item to the combobox
cbx.Items.Add(n)
File.Add(n)
noLocations = false
'select the new item in the combobox
If Not cbx.Items.Count = 0 Then
cbx.SelectedIndex = cbx.Items.Count - 1
End If
end sub
'This is the call the remove method that DOESN'T work
cbxMyControl.Remove(cbxMyControl.selectedindex)
'This is the Remove method that DOESN'T work.
Public Overridable Sub remove(ByVal i As Integer)
cbx.Items.Remove(i)
File.Remove(i)
Test = i
If Not cbx.Items.Count = 0 Then
cbx.SelectedIndex = 0
noLocations = False
Else
noLocations = True
End If
end sub


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
1
by: vimal patel via DotNetMonster.com | last post by:
hi, i want to remove array element from list. Suppose 5,6,7,8,9 is a array assigned. i want to remove element 7 from the array. How can i remove this? Please help me Thanks --
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
14
by: oLgAa25 | last post by:
Hello all, I am back I have this question everything compiles fine, but I just need to check for an index that is more than the array size. Although it says out of bound, but it is still...
19
by: brasilino | last post by:
Hi Folks: I've been looking (aka googling) around with no success. I need a usability beyond 'pop()' method when removing an Array elements. For example: oName = new...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
10
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.