This is a migrated thread and some comments may be shown as answers.

System.InvalidOperationException on RadTreeView OnGotFocus

5 Answers 124 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Ufficio Acquisti
Top achievements
Rank 1
Ufficio Acquisti asked on 20 Apr 2016, 04:25 PM

Hi, i'm using the latest Telerik release.

Only on some machines I got this error:

An exception was uncaught System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
   at Telerik.WinControls.UI.RadTreeViewElement.SynchronizeNodeElements()
   at Telerik.WinControls.UI.RadTreeViewElement.Update(UpdateActions updateAction)
   at Telerik.WinControls.UI.RadTreeView.OnGotFocus(EventArgs e)
   at System.Windows.Forms.Control.WmSetFocus(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadTreeView.WndProc(Message& m)

Here's my Code, where am I doing something wrong?

//user control Load event

this.Load += new System.EventHandler(this.TreeView_Load);

private void TreeView_Load(object sender, EventArgs e)
{
radTreeView1.BeginEdit();
PatientEpicrisis epicrisis = MyAdapter.ReadPatientEpicrisis();
var currentNode = this.radTreeView1.Nodes["EpicrisiNode"];
currentNode.Nodes.Clear();
if (!string.IsNullOrEmpty(epicrisis.Note))
{
currentNode.Nodes.Add(epicrisis.EpicrisisSynthesis);
var lastNode = currentNode.LastNode;
lastNode.Tag = epicrisis;
lastNode.EndEdit();
}
else
{
currentNode.ContextMenu = radContextMenuEpicrisis;
}
currentNode.EndEdit();
radTreeView1.EndEdit();
}

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Apr 2016, 01:37 PM
Hi Mara,

Thank you for writing.

You should remove the BeginEdit/EndEdit method calls. These methods should be used when you want programmatically start/end edit operation, they should not be called while you are updating the control.

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Ufficio Acquisti
Top achievements
Rank 1
answered on 21 Apr 2016, 01:40 PM
Thanks Dimitar, should I remove also the radTreeView1.BeginEdit() or just those called on the nodes?
0
Dimitar
Telerik team
answered on 21 Apr 2016, 01:52 PM
Hi Mara,

Yes, you should, this method puts the current node in edit mode. 

I hope this will be useful. 

Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Ufficio Acquisti
Top achievements
Rank 1
answered on 21 Apr 2016, 02:11 PM

Ok, I will try and let you know.

What is strange is that on many machines (mine included), either with BeginEdit() EndEdit() all is working fine.

Only on some other machines when the user tries to scroll, the application crashes with the exception I posted.

0
Dimitar
Telerik team
answered on 25 Apr 2016, 08:34 AM
Hello Mara,

Thank you for writing back.

I was not able to reproduce the exception either. Nevertheless, there is no point to put the control in edit mode while it is updated. So if the exception still occurs please try to find a clear way for its reproducing. This will allow us to properly investigate the case and provide you with a solution.

If you have any other questions, please do not hesitate to contact us.
 
Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Treeview
Asked by
Ufficio Acquisti
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Ufficio Acquisti
Top achievements
Rank 1
Share this question
or