In order to get things to work with an empty arraylist, you have to do two things.
1) Have your arraylist strongly typed by implementing ITypedList.
2) Make sure your derived object class (USState in the code below) has a default contructor.
In order to create the appropriate columns, the grid has to be able to get the information on the properties of the objects in your arraylist. The above steps facilitate this.
public class USArrayList : ArrayList, ITypedList
{
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
return TypeDescriptor.GetProperties(typeof(USState));
}
public string GetListName(PropertyDescriptor[] listAccessors)
{
return "USStatesList";
}
}
public class USState
{
private string myShortName ;
private string myLongName ;
private int _imageIndex;
public USState() //default constructor
{
this.myShortName = "";//"defaultShortName";
this.myLongName = "";//"defaultLongName";
this._imageIndex = -1;
}
// other code.....
}