Regression in .537: C1FlexGrid "Node.AddNode" fails

Posted by: wknauf on 12 April 2022, 6:52 pm EST

  • Posted 12 April 2022, 6:52 pm EST

    See attached sample: this call might fail:

    this.c1FlexGrid1.Rows[rowParent].Node.AddNode(NodeTypeEnum.LastChild, "Child");

    It will fail if you add nodes to an existing grid, and it will fail only if "BeginUpdate" is false.

    In my sample, I first create the root nodes, and afterwards I want to insert some child nodes for the first root node using "AddNode(NodeTypeEnum.LastChild, ...)".
    Here, the first child row is inserted at row "0" (header row) instead of row 2.

    Subsequent calls to "AddNode" will fail with an exception:
    Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    at C1.Win.C1FlexGrid.Node.AddNode(NodeTypeEnum position, Object data, Object key, Image img)
    at C1.Win.C1FlexGrid.Node.AddNode(NodeTypeEnum position, Object data)
    at C1FlexGridNodeAdd.Form1..ctor() in C:\Temp\C1FlexGridNodeAdd\Form1.cs:line 61

    But I think the main cause for this issue is, that the first child node is inserted at the wrong location and and thus the next insert will fail.

    Now I will try to find a workaround (our real world app is a bit more complex than the sample). If this is not possible, I will switch back to .532.

    Best regards
  • Replied 12 April 2022, 8:22 pm EST

    Here is a new sample that shows a more complex problem and a workaround:
    The tree now has three levels.
    When a button is clicked, I want to insert a child node of the first root node, see screenshot:

    Normally, this code should work ("intRowParent" is the grid row of the first root node where the new child node should be inserted):

    Node nodeChild = this.c1FlexGrid1.Rows[this.intRowParent].Node.AddNode(NodeTypeEnum.LastChild, "INSERTED");


    But again the issue happens: the node will be written in row 0. Note: it will not happen if "BeginUpdate/EndUpdate" is omitted.

    This workaround code inserts the node at the correct location

    private void button1_Click(object sender, EventArgs e)

    //Use a more complicated code to first insert a row, then initialize the "Node".
    //Unfortunately, "node.GetNode(NodeTypeEnum.LastChild)" gets the index of the last direct child of the parent node.
    //But we need the index of the last subchild at any tree level. So call a recursive function.
    int intRowInsertAfter = this.GetLastChildRowIndex(this.c1FlexGrid1.Rows[this.intRowParent].Node);

    int intRowInserted = this.c1FlexGrid1.Rows.Insert(intRowInsertAfter + 1).Index;
    this.c1FlexGrid1.Rows[intRowInserted].IsNode = true;
    this.c1FlexGrid1.Rows[intRowInserted].Node.Data = "INSERTED";
    this.c1FlexGrid1.Rows[intRowInserted].Node.Level = this.c1FlexGrid1.Rows[this.intRowParent].Node.Level + 1;


    /// <summary>
    /// Returns the row index of the last of child the node.
    /// This is a recursive method: if the node has children, it is called for the last child of this node.
    /// </summary>
    /// <param name="node"></param>
    /// <returns></returns>
    private int GetLastChildRowIndex(Node node)
    //End the recursion if the node has no children.
    if (node.Children > 0)
    Node nodeLast = node.GetNode(NodeTypeEnum.LastChild);

    return GetLastChildRowIndex(nodeLast);
    return node.Row.Index;

    Hope this issue can be fixed in the next hotfix release.
  • Replied 13 April 2022, 12:07 am EST

    Hi Wolfgang,

    We could see the issue at our end. We have reported the issue to the development team and will let you know as soon as we have an update.

    Kind Regards,

    [Internal Tracking ID: C1WIN-27243]
  • Replied 22 May 2022, 9:34 pm EST

    row.Node.AddNode(NodeTypeEnum.LastChild, text).Row;
    is throwing an exception. Please let me know the workaround or when it will be fixed.
  • Replied 22 May 2022, 11:07 pm EST

    Hi Virender,

    The ETA for the issue fix is the 2022v1 hotfix release. The 2022v1 hotfix release will be available around the end of May.

    Best Regards,
  • Replied 23 May 2022, 1:31 am EST

    My workaround is to add the child node to the end of the grid with this code snippet.
    The following code will only work if you fill the tree top down: first the parent node, then all child nodes recursive.

    So, you need the index of the parent row of the current node. Then, you can insert a child this way:

    int intRowChild = this.c1FlexGridTree.Rows.Add().Index;
    this.c1FlexGridTree.Rows[intRowChild].IsNode = true;
    this.c1FlexGridTree.Rows[intRowChild].Node.Data = "My node data"
    this.c1FlexGridTree.Rows[intRowChild].Node.Level = this.c1FlexGridTree.Rows[intRowParent].Node.Level + 1;

    Best regards

  • Marked as Answer

    Replied 24 May 2022, 10:46 pm EST

    Hi Wolfgang, Hi Virender,

    We are glad to inform you that this issue has been fixed in the latest 2022v1 hotfix release (4.5.20221.557). You can update to the latest version using the ComponentOne Control Panel or install the latest C1 packages using NuGet.

    Best Regards,
  • Replied 26 May 2022, 9:54 pm EST

    I can confirm that my sample works again, thanks.

  • Replied 26 May 2022, 11:46 pm EST

    I was too fast: my previous sample worked, but in our real app, there is a problem.

    Attached sample reproduces it: Up to line 81, the tree builds fine. But the last call to "AddNode" (line 122) writes the data to the wrong grid line, see screenshot: the marked text "Sänger Soli" should actually be a sibling node to to "Chor", which means it should be placed after "Bass". But it is inserted between "Chor-Heren" and "Tenor" and thus placed in the wrong row.

    The code creates a console output in this case, see helper method "AddNode"

    Best regards

  • Replied 29 May 2022, 6:10 pm EST

    Hi Wolfgang,

    We could observe the issue at our end. This seems like a bug. We have reported the issue to the development team and will let you know as soon as we have an update.


    Kind Regards,
  • Replied 2 August 2022, 4:59 pm EST

    Hi Wolfgang,

    We are happy to inform you that this issue has been fixed in the latest 2022v2 release. You can install the latest version of C1 Controls either from NuGet OR from the latest version of ComponentOne Control Panel. Links for both are given below.

    Kind Regards,
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels