System.InvalidOperationException on RadTreeView OnGotFocus

6 posts, 0 answers
  1. Mara
    Mara avatar
    5 posts
    Member since:
    Aug 2012

    Posted 20 Apr Link to this post

    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();
    }
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 21 Apr Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mara
    Mara avatar
    5 posts
    Member since:
    Aug 2012

    Posted 21 Apr in reply to Dimitar Link to this post

    Thanks Dimitar, should I remove also the radTreeView1.BeginEdit() or just those called on the nodes?
  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 21 Apr Link to this post

    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.
  6. Mara
    Mara avatar
    5 posts
    Member since:
    Aug 2012

    Posted 21 Apr in reply to Dimitar Link to this post

    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.

  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 25 Apr Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready