ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2016-12-20 20:32:13

adamcrowe
Member
Registered: 2016-08-21
Posts: 21

StackOverflow

Hello,

I've been trying to debug this all evening but I can't understand why the following code in Borders.cs iterates forever and generates a StackOverflow exception:

private void SetVBorders(int row, int col, int rows, RangeBorderStyle borderStyle, VBorderOwnerPosition pos)
{
    ...

    if (cell1 != null && cell2 != null && !cell1.MergeStartPos.IsEmpty && CellPosition.Equals(cell1.MergeStartPos, cell2.MergeStartPos))
    {
        tr = k;
        nextStartRow = cell2.MergeEndPos.Row + 1;
        break;
    }

    ...

    // if border splitted by merged range, set the remains
    if (nextStartRow != -1)
    {
        SetVBorders(nextStartRow, col, r2 - nextStartRow, borderStyle, pos);
    }
}

When certain merged cells get copied and pasted, SetVBorders iterates forever until an exception occurs sad((

Offline

#2 2016-12-20 22:10:27

adamcrowe
Member
Registered: 2016-08-21
Posts: 21

Re: StackOverflow

1. It is definitely border related. When no border is set manually, this error doesn't occur.
2. It often occurs when a you copy a range that contains a merged cell and a border, and the paste is then applied to a range that would overlap the original range (but sometimes another range as well - I cannot find what is in common).
3. I can confirm this error happens on version 2.0 as well.

Desperate for help.

Thank you!

Offline

#3 2016-12-23 11:37:02

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: StackOverflow

It is very difficult to solve this problem without a detailed steps to reappear it. We should find a way to force it happen firstly.

Last edited by Jingwood (2016-12-23 11:37:19)

Offline

#4 2016-12-23 12:59:06

adamcrowe
Member
Registered: 2016-08-21
Posts: 21

Re: StackOverflow

Thank you Jing,

1. Please create a worksheet the size of 5 rows x 48 columns.
2. Merge cells A24 to A32 and add a solid All border around this range, and type some text.
3. Copy and paste cells A24:A32 to A22 to get error.

If this sort of copy and paste is not possible, then at least there should be a way to detect it and prevent the user from doing it.

Thank you!

Adam

Offline

#5 2016-12-25 06:10:04

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: StackOverflow

5 rows x 48 columns? not 48 rows x 5 columns? Because you want to merge row 24 to 32...

I have tested by using Editor GUI, resize worksheet to 48 rows x 5 columns, merge row 24 to 32 and try copy to row 22, because paste will modify another merged cell, the operation was aborted and nothing happened.

If the error happens by executing some code, it will be helpful if you can post the code, thanks.

Offline

#6 2016-12-25 06:43:28

adamcrowe
Member
Registered: 2016-08-21
Posts: 21

Re: StackOverflow

Many apologies Jing, I got the cell naming wrong, but I did mean 5 rows and 48 columns. The error happens when a bunch of horizontally merged cells are copy and pasted so the above steps should have been:

1. Please create a worksheet the size of 5 rows x 48 columns.
2. Merge cells K1 to T1 and add a black solid All border around this range, and type some text. The border is the critical part.
3. Copy and paste cells K1:T1 to I1 to get error.

If this doesn't recreate the error, I will post the RGF source next week when I'm back at my computer.

Thank you very very much!

Adam

Offline

#7 2016-12-27 11:55:43

adamcrowe
Member
Registered: 2016-08-21
Posts: 21

Re: StackOverflow

One more thing... After spending so much time with the code, I take some of the earlier stuff for granted. It's worth mentioning that I have a bunch of code written in the BesorePaste event. The reason for this code is because when you paste a range that, for example, has a couple of merged cells to a range that has a different existing merge arrangement, the paste doesn't come out right. So I wrote this code to clear the affected range from any merged cells and pre-existing data. This way the paste works perfectly, apart from the condition that I mentioned before which causes a StackOverflow exception on SetVBorder.

        private void Sheet_BeforePaste(object sender, unvell.ReoGrid.Events.BeforeRangeOperationEventArgs e)
        {
                for (int row = e.Range.Row; row <= e.Range.EndRow; row++)
                {
                    for (int col = e.Range.Col; col <= e.Range.EndCol; col++)
                    {
                        if (sheet.Cells[row, col].IsMergedCell)
                        {
                            sheet.UnmergeRange(row, col, sheet.Cells[row, col].GetRowspan(), sheet.Cells[row, col].GetColspan());
                        }
                    }
                }

                sheet.Ranges[sheet.SelectionRange].Data = "";
        }

Thank you once again!

Adam

Offline

#8 2016-12-28 12:12:08

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: StackOverflow

Thanks Adam, I will check it...

Offline

Board footer

Powered by FluxBB