ArgumentOutOfRangeException When I Remove ListView items
- From: "dvestal@xxxxxxxxx" <dvestal@xxxxxxxxx>
- Date: 23 May 2007 13:32:17 -0700
I have a ListView with checkboxes. I want to remove items when the
checkboxes are unchecked, but to do so yields an
ArgumentOutOfRangeException. Is there an easy way to get around this?
A simple program that illustrates the exception is below:
using System;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form frm = new Form();
frm.Load += new EventHandler(frm_Load);
Application.Run(frm);
}
static void frm_Load(object sender, EventArgs e)
{
ListView list = new ListView();
list.CheckBoxes = true;
list.ItemCheck += new ItemCheckEventHandler(list_ItemCheck);
((Form) sender).Controls.Add(list);
ListViewItem item = new ListViewItem("An Item");
list.Items.Add(item);
item.Checked = true;
}
static void list_ItemCheck(object sender, ItemCheckEventArgs e)
{
((ListView) sender).Items.RemoveAt(e.Index);
// Exception is thrown after leaving this handler.
// How can I safely remove this ListView item?
}
}
}
.
- Follow-Ups:
- Re: ArgumentOutOfRangeException When I Remove ListView items
- From: Ashot Geodakov
- Re: ArgumentOutOfRangeException When I Remove ListView items
- Prev by Date: Re: Declaring variables in loops
- Next by Date: Re: Serialization vs. program updates
- Previous by thread: XPathNavigator SetValue wipes out XmlType
- Next by thread: Re: ArgumentOutOfRangeException When I Remove ListView items
- Index(es):
Relevant Pages
|
Loading