473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Checked Item from CheckedListView

I want to iterate through a CheckedListView and delete the checked items ONLY.
Anybody know how to do this? Anybody know a rock solid way of doing this?
I have tried the following but get an exception

unhandled exception of type System.InvalidOperationException in
system.windows.forms.dll

Additionlal Info: The list that this enumerator is bound to has been
modified.
An enumerator can only be used if the list dosn't change.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim indexChecked, itemCount As Integer
Dim itemChecked As Object = ChkListBoxRoutines.CheckedItems

For Each itemChecked In itemChecked
ChkListBoxRoutines.Items.RemoveAt(indexChecked)
ChkListBoxRoutines.Refresh()
Next
End Sub



Nov 21 '05 #1
5 1947
Wht is "itemChecked"? I usually fill a collection with items to remove
first, in order that I don't modify the collection while I'm iterating it.
Dim toRemove as New ArrayList

For Each theItem As <someclass> In <somecollectiontoremovefrom>
toRemove.Add ( theItem )
Next

For Each toRemove As <someclass> In toRemove
<somecollectiontoremovefrom>.Remove ( toRemove )
Next
(also please use option strict on - it makes your code a lot more
robust....)

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
I want to iterate through a CheckedListView and delete the checked items
ONLY.
Anybody know how to do this? Anybody know a rock solid way of doing this?
I have tried the following but get an exception

unhandled exception of type System.InvalidOperationException in
system.windows.forms.dll

Additionlal Info: The list that this enumerator is bound to has been
modified.
An enumerator can only be used if the list dosn't change.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim indexChecked, itemCount As Integer
Dim itemChecked As Object = ChkListBoxRoutines.CheckedItems

For Each itemChecked In itemChecked
ChkListBoxRoutines.Items.RemoveAt(indexChecked)
ChkListBoxRoutines.Refresh()
Next
End Sub


Nov 21 '05 #2
Sorry Robin,
I don't understand your code too well
It's the <someclass> & <somecollectiontoremovefrom> I need help with.
Can you post a working example if you have time, I'ld really appreciate it.
marc
"Robin Tucker" wrote:
Wht is "itemChecked"? I usually fill a collection with items to remove
first, in order that I don't modify the collection while I'm iterating it.
Dim toRemove as New ArrayList

For Each theItem As <someclass> In <somecollectiontoremovefrom>
toRemove.Add ( theItem )
Next

For Each toRemove As <someclass> In toRemove
<somecollectiontoremovefrom>.Remove ( toRemove )
Next
(also please use option strict on - it makes your code a lot more
robust....)

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
I want to iterate through a CheckedListView and delete the checked items
ONLY.
Anybody know how to do this? Anybody know a rock solid way of doing this?
I have tried the following but get an exception

unhandled exception of type System.InvalidOperationException in
system.windows.forms.dll

Additionlal Info: The list that this enumerator is bound to has been
modified.
An enumerator can only be used if the list dosn't change.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim indexChecked, itemCount As Integer
Dim itemChecked As Object = ChkListBoxRoutines.CheckedItems

For Each itemChecked In itemChecked
ChkListBoxRoutines.Items.RemoveAt(indexChecked)
ChkListBoxRoutines.Refresh()
Next
End Sub



Nov 21 '05 #3
Something like this:
Private Sub deleteButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles deleteButton.Click

Dim toRemove As New ArrayList

For Each theItem As Object In CheckedListBox1.CheckedItems
toRemove.Add(theItem)
Next

For Each theItem As Object In toRemove
CheckedListBox1.Items.Remove(theItem)
Next

End Sub
"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...
Sorry Robin,
I don't understand your code too well
It's the <someclass> & <somecollectiontoremovefrom> I need help with.
Can you post a working example if you have time, I'ld really appreciate
it.
marc
"Robin Tucker" wrote:
Wht is "itemChecked"? I usually fill a collection with items to remove
first, in order that I don't modify the collection while I'm iterating
it.
Dim toRemove as New ArrayList

For Each theItem As <someclass> In <somecollectiontoremovefrom>
toRemove.Add ( theItem )
Next

For Each toRemove As <someclass> In toRemove
<somecollectiontoremovefrom>.Remove ( toRemove )
Next
(also please use option strict on - it makes your code a lot more
robust....)

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
>I want to iterate through a CheckedListView and delete the checked items
>ONLY.
> Anybody know how to do this? Anybody know a rock solid way of doing
> this?
> I have tried the following but get an exception
>
> unhandled exception of type System.InvalidOperationException in
> system.windows.forms.dll
>
> Additionlal Info: The list that this enumerator is bound to has been
> modified.
> An enumerator can only be used if the list dosn't change.
>
> Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnDelete.Click
> Dim indexChecked, itemCount As Integer
> Dim itemChecked As Object = ChkListBoxRoutines.CheckedItems
>
> For Each itemChecked In itemChecked
> ChkListBoxRoutines.Items.RemoveAt(indexChecked)
> ChkListBoxRoutines.Refresh()
> Next
> End Sub
>
>
>
>
>
>
>


Nov 21 '05 #4
thanks Robin Ill try it
marc

"Robin Tucker" wrote:
Something like this:
Private Sub deleteButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles deleteButton.Click

Dim toRemove As New ArrayList

For Each theItem As Object In CheckedListBox1.CheckedItems
toRemove.Add(theItem)
Next

For Each theItem As Object In toRemove
CheckedListBox1.Items.Remove(theItem)
Next

End Sub
"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...
Sorry Robin,
I don't understand your code too well
It's the <someclass> & <somecollectiontoremovefrom> I need help with.
Can you post a working example if you have time, I'ld really appreciate
it.
marc
"Robin Tucker" wrote:
Wht is "itemChecked"? I usually fill a collection with items to remove
first, in order that I don't modify the collection while I'm iterating
it.
Dim toRemove as New ArrayList

For Each theItem As <someclass> In <somecollectiontoremovefrom>
toRemove.Add ( theItem )
Next

For Each toRemove As <someclass> In toRemove
<somecollectiontoremovefrom>.Remove ( toRemove )
Next
(also please use option strict on - it makes your code a lot more
robust....)

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
>I want to iterate through a CheckedListView and delete the checked items
>ONLY.
> Anybody know how to do this? Anybody know a rock solid way of doing
> this?
> I have tried the following but get an exception
>
> unhandled exception of type System.InvalidOperationException in
> system.windows.forms.dll
>
> Additionlal Info: The list that this enumerator is bound to has been
> modified.
> An enumerator can only be used if the list dosn't change.
>
> Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnDelete.Click
> Dim indexChecked, itemCount As Integer
> Dim itemChecked As Object = ChkListBoxRoutines.CheckedItems
>
> For Each itemChecked In itemChecked
> ChkListBoxRoutines.Items.RemoveAt(indexChecked)
> ChkListBoxRoutines.Refresh()
> Next
> End Sub
>
>
>
>
>
>
>


Nov 21 '05 #5
>Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim indexChecked, itemCount As Integer
Dim itemChecked As Object = ChkListBoxRoutines.CheckedItem*s For Each itemChecked In itemChecked
ChkListBoxRoutines.Items.Remov*eAt(indexChecked)
ChkListBoxRoutines.Refresh()
Next
End Sub

Try using Remove() instead of RemoveAt(). The following worked for me

For Each itm As ListViewItem In lvwMain.CheckedItems
lvwMain.Items.Remove(itm)
Next

There was no need for a refresh - repainted itself after removing the
items.

Nov 21 '05 #6

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

Similar topics

1
1922
by: Qnavry | last post by:
I am creating one page to edit, delete, and add data to a database. The Add code works but the Edit and Delete do not. What am I doing wrong? If you need more code let me know. Thanks Code:...
2
1607
by: ad | last post by:
I want to delete a DataRowView in a DataView if the DataRowView not checked OK. (CheckRow is a function for checking ) I used the codes below: But when some row is delete, it fail , the error...
3
2890
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
14
5667
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
0
1252
by: Mike Wertheim | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
4
2156
by: MasterChief | last post by:
I am trying to learn how to delete multple items in a database using the code behind file. I would just like somebody to tell me what is wrong with my code. I am new to connecting to the database...
3
1615
by: Charleees | last post by:
Hi all, I have a DataGrid With Template Columns.. In the First Column i have a Check Box... Also i have a Button Outside the DataGrid..Just Above it.. What i want to do is .... I have to...
5
12020
by: streamkid | last post by:
i have a class table, which has a vector of records(-db). i 'm trying to remove an element, but it doesn't seem to work.. i read this http://www.cppreference.com/cppvector/erase.html] and that's...
0
1709
by: =?Utf-8?B?TWVlbWEgSnVkeQ==?= | last post by:
I have a Verizon Palm Treo 755p and use Outlook 2002 on my new HP Pavilion (Vista 64-bit). When I was syncing on my old XP PC, everything worked fine. On the Vista PC, when I finally got it to...
0
7326
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
7383
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
7046
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...
0
5627
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,...
1
5053
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
4707
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
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
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 ...
0
418
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...

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.