DataTree not raising BeforeAddRow/AfterAddRow

Posted by: aruud on 16 October 2019, 4:57 am EST

  • Posted 16 October 2019, 4:57 am EST

    Hello support!

    We encountered a case where the DataTree ( https://www.grapecity.com/samples/datatree ) was a perfect fit, and it has worked well for the most part. However, my use-case requires me to set auto-incrementing string values whenever a new row is added (Think "Sample 1", "Sample 2", etc.). Since they're strings, I can't use the auto-increment feature of the DataTables bound to the DataTree. I have attached handlers to both the BeforeAddRow and AfterAddRow events, but they never seem to fire. Even when added as a custom override in the DataTree itself:

            public void ShowChildLevel()
    {
    C1FlexDataTree parent = this;
    int level = 0;

    while (parent.Parent is C1FlexDataTree)
    {
    level++;
    parent = parent.Parent as C1FlexDataTree;
    }

    if (level == 0)
    {
    MessageBox.Show("I am parent");
    }
    else
    {
    MessageBox.Show("I am child: " + level.ToString());
    }
    }

    protected override void OnAfterAddRow(RowColEventArgs e)
    {
    ShowChildLevel();

    base.OnAfterAddRow(e);
    }


    neither event ever fires. I've overriden other events and can see them trigger breakpoints, so it's not something wrong with the overriding or attaching in themselves. I can't see anything in the DataTree that would be supressing these events, so I'm at a loss.

    While testing the problem, I noticed that the AfterDragColumn event also doesn't fire in the general case, but does fire when the whole DataTree is selected. I don't need the AfterDragColumn event, but it may be a clue as to the cause.

    I'm currently looking at ways to try and trigger the AddRow events manually using the events I know do fire, but I'd really prefer to use those events directly.

    Cheers,
    -Alex
  • Replied 16 October 2019, 5:07 pm EST

    Hello Alex,

    You need to add the code snippet given below in the ** helper class region of C1FlexDataTree.cs file to handle the AfterAddRow event :
    public void ShowChildLevel()
    {
    C1FlexDataTree parent = Parent as C1FlexDataTree;
    int level = 0;
    while (parent.Parent is C1FlexDataTree)
    {
    level++;
    parent = parent.Parent as C1FlexDataTree;
    }

    if (level == 0)
    {
    MessageBox.Show("I am parent");
    }
    else
    {
    MessageBox.Show("I am child: " + level.ToString());
    }
    }
    protected override void OnAfterAddRow(RowColEventArgs e)
    {
    ShowChildLevel();
    base.OnAfterAddRow(e);
    }


    I had modified the sample as per the above given solution , please have a look.

    Regards,
    Prabhat Sharma.
    DataTree.zip
  • Replied 17 October 2019, 8:53 am EST

    Hello Prabhat,

    Ah, perfect, thank you for the quick reply! I saw that there were overriden events in that section, but didn't even think to try placing my additions there. Should all future events generally be overriden there, or does it differ on a per-event basis?

    Apologies for not finding the solution myself, and thanks again!

    -Alex
  • Marked as Answer

    Replied 17 October 2019, 8:43 pm EST

    Hello,

    As per the code given below in the GridHeader class constructor :

    parent.Controls.Add(this);

    It shows that C1FlexDataTree works like a container which contains multiple FlexGrids so if you want to handle any event for FlexGrid related task, you should override it there only.

    Regards,
    Prabhat Sharma
Need extra support?

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

Learn More

Forum Channels