By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,685 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
Cor
Hi Don,

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

Cor
Nov 20 '05 #2

P: n/a
* "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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.