How to walk thru Child rows and grandchildren rows?

Posted by: john-shugart on 8 September 2017, 2:22 pm EST

  • Posted 8 September 2017, 2:22 pm EST

    I have a hierarchial grid where I have parent rows, children rows and grandchildren rows. When a user clicks on a Parent row, I want to open up the children and grandchildren rows for edit for this parent.


    Can you help me achieve this behavior?


    Thanks in advance,


    John

  • Replied 8 September 2017, 2:22 pm EST

    Hello John,


    Please have a look at the attached sample wherein on clicking the expand icon in the row header we are able to open its children and grandchildren rows as well by trapping it in Spread's ChildViewCreated event and you can edit them by double clicking in the particular cells.


    Hope this will help you. Thanks.


    2010/06/ExpandAllChildren.zip
  • Replied 8 September 2017, 2:22 pm EST

    Reeva,


    Thanks for the code, it works well! I want to be able to set all 3 levels of my grids operation mode to normal, or readonly. I want to open the grid up for edit, when an edit button is pressed, then when a save or cancel button is pressed, I'd like to close the grid to edit.


    Is there a way to accomplish this? 


    Thanks in advance,


    John 


     

  • Replied 8 September 2017, 2:22 pm EST

    Hello John,


    After Expanding all the children of parent Node we can edit it and then On Click of Save button, if you have your Spread control bound to the hierarchial dataset, then when you query the DataSource property of the Spread, you would get the entire DataSet. You should be able to go through the DataTables in the DataSet to get all the changes and write them back. Or, if you are using an adapter (SQLDataAdapter or OLEDBDataAdapter), you should be able to update the entire DataSet with one call to the Update method using EndEdit() which pushes changes since the last BeginEdit or AddNew call into the underlying object.


    Then to close all the nodes after saving in database you can call the below given code on a click of a button:


    <BLOCKQUOTE>

           private void btnCloseAll_Click(object sender, EventArgs e)
            {
                bool b;
                for (int i = 0; i < fpSpread1.ActiveSheet.Rows.Count - 1; i++)
                {
                    b = fpSpread1.ActiveSheet.IsRowExpanded(i);
                    if (b == true)
                        fpSpread1.ActiveSheet.ExpandRow(i, false);
                }
            }

    </BLOCKQUOTE>

    Hope this will help you. Thanks.

Need extra support?

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

Learn More

Forum Channels