Hello All,
I have been trying to solve the following issue and it seems like there
is no solution available any where and maybe people at Microsoft should
may be of some help.
I am writing a .Net desktop application using C# and framework version
1.1
I have a arraylist of some objects of the same type and I am showing
them in a datagrid using
Daragrid1. DataSource = objArray;
When I try to delete any of the rows from the datagrid I get the
following error message.
An unhandled exception of type 'System.IndexOutOfRangeException'
occurred in system.windows.forms.dll
Additional information: No value at index 1
Here is a code snippet
public class Customer
{
private string _customerName;
public Customer (string name)
{
_customerName = name;
}
public string CustomerName
{
get { return _customerName ;}
set { _customerName = value;}
}
}
public class Customerlist
{
public ArrayList customerList;
Customerlist()
{
customerList = new ArrayList();
customerList.Add(new Customer ("John"));
customerList.Add(new Customer ("Doe"));
customerList.Add(new Customer ("Dave"));
}
public void Remove (int i )
{
customerList.RemoveAt(i);
}
}
In my form I create a variable of Customerlist and bind it to the grid
as
dg1.DataSource = Customerlist.customerList;
I have a button, when I select a row in the grid and hit Delete I do
the following
dg1.DataSource = null;
customerList.Remove ( dg1.currentRowIndex);
dg1.DataSource = Customerlist.customerList;
After this code is called I get the above error. Has anyone solved this
problem. I will be thankful if some one can give me the solution.
Thanks
nad