Unable to Remove Rows from a Group in Spread.NET

Posted by: hamid.naeemi on 17 April 2024, 2:00 pm EST

    • Post Options:
    • Link

    Posted 17 April 2024, 2:00 pm EST

    I am encountering an issue with Spread.NET where I cannot remove a row from a group. According to the documentation, the GroupDataModel class does not support direct modifications to the row or column count. It suggests using the original data model methods for adding or removing rows or columns.

    However, the GroupDataModel.TargetModel property returns an ISheetDataModel, which does not provide methods to remove rows. Additionally, the underlying type of TargetModel is WorksheetDataModel, which is an internal class with inaccessible members.

    Expected Behavior: There should be a method or workaround to remove rows from a group using the GroupDataModel or through its TargetModel property.

    Steps to Reproduce:

    Create a group in the worksheet.

    Attempt to remove a row from the group using the methods provided by GroupDataModel.

    Documentation Reference: The documentation states: “The GroupDataModel does not support changing the column or row count. To add or remove columns or rows, you need to call the original data model methods. You can access the original data model using the TargetModel property of the GroupDataModel class.”

    Could you please provide guidance or a workaround on how to remove rows from a group in this scenario?

  • Posted 18 April 2024, 8:50 am EST

    Hi hamid,

    You can remove the row from a grouped FpSpread’s SheetView by accessing the original data model using the TargetModel property of the GroupDataModel class. When GroupDataModel.TargetModel property returns an ISheetDataModel, you can cast it into DefaultSheetDataModel type for removing the desired row. Here is the code snippet for same:

    GroupDataModel mainGroupDM = new GroupDataModel(fpSpread1_Sheet1.Models.Data);
    while (mainGroupDM.TargetModel is GroupDataModel)
    {
        mainGroupDM = (mainGroupDM.TargetModel as GroupDataModel);
    }
    var  defaultSheetDataModel = mainGroupDM.TargetModel as DefaultSheetDataModel;
    if(defaultSheetDataModel != null)
    {
        if(defaultSheetDataModel.RowCount > 1)
        {
            defaultSheetDataModel.RemoveRow(1);  // row is removed based on the index of row in original data model
        }
    }

    Kindly refer to the attached sample for full implementation. See GroupRemoveRow.zip

    Thanks & Regards,

    Aastha

  • Posted 18 April 2024, 9:08 am EST

    Thanks Aastha

    It worked, It would be very helpful this could be available in documents. very far from what said in documentation.

  • Posted 19 April 2024, 6:03 am EST

    Hi Hamid,

    Thanks for the acknowledgement.

    We have forwarded your request to the concerned team. We will keep you posted with further updates regarding this.

    Thanks & Regards,

    Aastha

Need extra support?

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

Learn More

Forum Channels