I have a test data item class defined as follows:
public class DataItem : IListSource
{
private string _Name;
public string Name
{
get{ return _Name; }
set{ _Name = value; }
}
private string _Value;
public string Value
{
get{ return _Value; }
set{ _Value = value; }
}
private ArrayList _SubItems;
public DataItem(int depth, int subItemsCount)
{
_SubItems = new ArrayList();
_Name = \"Name\"+IdCounter.ToString();
_Value = \"Value\"+IdCounter.ToString();
IdCounter++;
if( depth > 0 )
{
for(int i=0; i _SubItems.Add(new DataItem(depth-1,subItemsCount));
}
}
private static int IdCounter = 1;
#region IListSource Members
public System.Collections.IList GetList()
{
return _SubItems;
}
public bool ContainsListCollection
{
get
{
return _SubItems.Count > 0;
}
}
#endregion
}
Create a new empty form and put a FlyGrid on it.
Add two standard columns to the grid: HierarchyColumn and Column.
Assign FieldName properties of the columns to the \"Name\" and \"Value\" values correspondingly.
In the folrm's OnLoad event handler initialize and attach test data source to the grid:
private ArrayList _DataItems;
private void Form1_Load(object sender, System.EventArgs e)
{
_DataItems = new ArrayList();
_DataItems.Add(new DataItem(3,6));
_DataItems.Add(new DataItem(3,6));
_DataItems.Add(new DataItem(3,6));
flyGrid1.Rows.DataSource = _DataItems;
}
Now start the test application.
Hierarchical data displayed OK.
Open any branch of the tree untill the leaf nodes.
Edit first three nodes of the leaf node group. They are edited fine.
Edit last three nodes of the leaf node group.
Unhandled exception thrown:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at ..EndEdit(Int32 index)
at NineRays.Windows.Forms.Data.Rows.(NodeBase , Int32 )
at NineRays.Windows.Forms.Data.Rows.(Object , NodeBase )
at NineRays.Windows.Forms.Data.RootNode.8(NodeBase )
at NineRays.Windows.Forms.Data.NodeBase.OnFocusChanging()
at NineRays.Windows.Forms.Data.NodeBase.set_Focused(Boolean value)
at NineRays.Windows.Forms.Data.Rows.(NodeBase )
at NineRays.Windows.Forms.FlyGrid.OnMouseDown(MouseEventArgs me)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at NineRays.Windows.Forms.FlyGrid.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The reason is that the flyGrid tries to pass indexes of the most inner list to the most outer list of the data items, when it queries data fields for updated values.
Since the outer list contains only 3 items and inner list 6, ArgumentOutOfRangeException is being thrown by the ArrayList indexer when the index is greater than 2 (last three nodes of the inner list).
Could you please fix this issue?
Thank you.
PS: tested with FlyGrid version 1.4.0.18 in VS 2003.