This is a migrated thread and some comments may be shown as answers.

SpreadSheet Cell changed event infinite loop.

4 Answers 334 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
Psyduck asked on 11 Mar 2021, 01:13 PM

 

Hello.

When using the Cell Change Event, if you use ClearFill(), it takes an infinite loop. Is there any way to prevent this?

xaml - radspreadsheet < ActiveSheetChanged="radSpreadsheet_ActiveSheetChanged" />
 
C# Code
private void radSpreadsheet_ActiveSheetChanged(object sender, EventArgs e)
{
  radSpreadsheet.ActiveWorksheet.Cells.CellPropertyChanged += cells_CellPropertyChanged;
}
 
private void cells_CellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
        {
            var isSameValue = e.Property.UseSameValueAsPreviousOnInsert;
            var column = e.CellRange.FromIndex.ColumnIndex;
            var row = e.CellRange.FromIndex.RowIndex;
            CellSelection cell = (sender as Cells)[row, column];
            var value = cell.GetValue().Value.RawValue;
            if (string.IsNullOrEmpty(value))
            {
                cell.SetFill(Defines.RedFill);
                if (column == 2)
                {
                    cell.Worksheet.Rows[row].Remove();
                }
            }
            else if (value == Defines.NoParam)
            {
                cell.SetFill(Defines.YellowFill);
            }
            else
            {
                cell.ClearFill(); // This cellChanged event loop.
            }
        }

 

Thanks.

 

4 Answers, 1 is accepted

Sort by
1
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
answered on 12 Mar 2021, 05:27 AM

Find a similar example. I solved it myself.

private bool IsUpdate = false;
        private void cells_CellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
        {
            if(IsUpdate == false && e.Property == CellPropertyDefinitions.ValueProperty)
            {
                IsUpdate = true;
                CellSelection cell = (sender as Cells)[e.CellRange];
                var values = cell.GetValue().Value.RawValue;
                if (string.IsNullOrEmpty(values) || values.Equals(Defines.NoValue))
                {
                    cell.SetFill(Defines.RedFill);
                }
                else if (values.Equals(Defines.NoParam))
                {
                    cell.SetFill(Defines.YellowFill);
                }
                else
                {
                    cell.ClearFill();
                }
            }
            IsUpdate = false;
        }

 

When the cells_CellPropertyChanged function is finished, an error is displayed showing message.

 

LocalizationManager.GetString("Spreadsheet_ProtectedWorksheet_Error"); => The cell you are trying to change is on a protected sheet. To make changes, unprotect the sheet.

 

message e.content => The collection has been modified. Enumeration operations may not run. 

 

 

0
Martin
Telerik team
answered on 16 Mar 2021, 09:46 AM

Hi Kim,

Thank you for the provided feedback and code snippets.

It seems you are hitting a regression issue in the CellPropertyChanged event. I logged an item on your behalf in our backlog to fix it: Spreadsheet: InvalidOperationException is thrown when attaching to CellPropertyChanged event and trying to modify the cell. I am afraid I cannot provide you with a workaround until this bug is fixed, so please, make sure to subscribe to the task so you can receive updates when its status changes.

In appreciation for bringing this to our attention, I updated your Telerik points.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
answered on 19 Mar 2021, 01:32 AM

Hello.

 

The error must have been corrected, but is there any documentation on it?

If there is feedback, can you let me know when?

 

Thanks.

0
Martin
Telerik team
answered on 19 Mar 2021, 11:04 AM

Hello Kim,

I want to apologize for the inconvenience this issue might be causing you but it is still not fixed. All the related information including its status can be followed in the public item: Spreadsheet: InvalidOperationException is thrown when attaching to CellPropertyChanged event and trying to modify the cell. Please, make sure you are following it in order to be notified when there is a change in its status.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Spreadsheet
Asked by
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
Answers by
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
Martin
Telerik team
Share this question
or