J
Jim Balo
Hi,
When I bind a BindingList<> to a DataGridView and then call RemoveAt(n) on
it, I get ArgumentOutOfRange. Could someone explain why?
Sample:
public partial class TestForm2 : Form
{
private BindingList<Person> _personList = new BindingList<Person>();
public TestForm2()
{
InitializeComponent();
}
private void TestForm2_Load(object sender, EventArgs e)
{
Person personA = new Person("Pete");
Person personB = new Person("James");
_personList.Add(personA);
_personList.Add(personB);
uxTestGrid.DataSource = _personList;
}
private void uxTestButton_Click(object sender, EventArgs e)
{
_personList.RemoveAt(0);
}
}
public class Person
{
public string Name = "";
public Person(string name)
{
Name = name;
}
}
So I have two Person objects in the BindingList. Yet, when I call
_personList.RemoveAt(0) (or 1), I get this exception. If I do not bind it
to the DataGridView, it works fine.
Please help.
Thanks,
Jim
When I bind a BindingList<> to a DataGridView and then call RemoveAt(n) on
it, I get ArgumentOutOfRange. Could someone explain why?
Sample:
public partial class TestForm2 : Form
{
private BindingList<Person> _personList = new BindingList<Person>();
public TestForm2()
{
InitializeComponent();
}
private void TestForm2_Load(object sender, EventArgs e)
{
Person personA = new Person("Pete");
Person personB = new Person("James");
_personList.Add(personA);
_personList.Add(personB);
uxTestGrid.DataSource = _personList;
}
private void uxTestButton_Click(object sender, EventArgs e)
{
_personList.RemoveAt(0);
}
}
public class Person
{
public string Name = "";
public Person(string name)
{
Name = name;
}
}
So I have two Person objects in the BindingList. Yet, when I call
_personList.RemoveAt(0) (or 1), I get this exception. If I do not bind it
to the DataGridView, it works fine.
Please help.
Thanks,
Jim