Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SheetChangeEventHandler Problem
Hi everyone!
Im running into a problem using SheetChangeEventHandler. We need to develop an application that binds to that event. When a cell value changes we need to get that value and see if it is on a given row and column and if matches a list of rows and columns we take that value and insert it in a sql server 2005 table. The problem we are facing now is that after changing some cells and inserting the values on sql, the application stops to receive the SheetChangeEventHandler event. I dont know why, the code seems right but it keeps happening and the application doesnt catch any exception that might be thrown. For example, you change one cell and the event fires resulting in the value inserted in the sql server table. Then you change a few more with the same results. Then you change another cell and nothing happens, the event doesnt get fired and as a result the data is not inserted in the sql server table. The application is very simple. Is just a Windows Form that shows what is doing the app, we connect to Excel at Form_Load where we set the delegate for the event and the event implementation where we get the value and insert it on the database. Form_Load objApp = (Excel.Application)System.Runtime.InteropServices. Marshal.GetActiveObject("Excel.Application"); objApp.ActiveWorkbook.SheetChange += new Microsoft.Office.Interop.Excel.WorkbookEvents_Shee tChangeEventHandler(ActiveWorkbook_SheetChange); Event Implementation void ActiveWorkbook_SheetChange(object Sh, Microsoft.Office.Interop.Excel.Range Target) { try { if (!IsNumeric(Target.Value2)) { MessageBox.Show("Cell value is not numeric", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string columna_excel = "R" + Target.Row + "C" + Target.Column; lblmensajes.Text = "Updating data..." + columna_excel; int result = data.SaveValue(columna_excel, Convert.ToDecimal(Target.Value2), fecha); if (result == 0) { data.UpdateControlTable(id_proveedor, "ult_actualizacion", "GetDate()"); lblmensajes.Text = "Data was updated sucessfully."; } else { data.UpdateControlTable(id_proveedor, "error_int", result.ToString()); lblmensajes.Text = "Error! Data was not updated."; } } catch (Exception ex) { this.messsageForm.AddMessage(ex.ToString()); MessageBox.Show(ex.ToString()); } } I hope that anyone can help me. Thanks in advance!!! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Colon at the end of excel file name(ex: problem.xls:1, problem.xls | New Users to Excel | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) | |||
problem with a conditional max problem | Excel Discussion (Misc queries) | |||
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? | Excel Programming |