anonymous usertuardo-7580
I couldn't reproduce this error, I put it there for about ten minutes and tested it again and the event was still triggered correctly.
The biggest possibility is that the object is released by the garbage collector.Try to set Excel.Application, Excel.Workbook, Excel.Worksheet as global variables to see if it is useful.
Worksheet.SelectionChange get lost after some time
Hello,
In a VSTO addin for Excel, developed in C#, I am creating a sheet this way:
public void Populate(List<Systems.Models.Producto> productos)
{
Excel.Workbook workbook = _excelApp.ActiveWorkbook;
Excel.Worksheet worksheet = workbook.Sheets.Add(After: workbook.Sheets[workbook.Sheets.Count]);
worksheet.SelectionChange += Worksheet_SelectionChange;
worksheet.Name = "Inventario";
// More instructions
}
Well... I have noticed that Worksheet_SelectionChange
is called for a moment when I select any cell in the sheet. After a few minutes later, that event is not called anymore.
At first, I thought that the object that owns the method populate
was being disposed. That could sound strange since this object owns the sheet also so that while the sheet is not closed, the object will be alive. However, just in case, I have declared the object that owns the method populate
globally to the parent object, but the same problem occurs.
Any help will be appreciated. Thanks
Jaime
1 answer
Sort by: Most helpful
-
Timon Yang-MSFT 9,571 Reputation points
2021-04-26T08:34:09.03+00:00