473,394 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Loosing event handlers in word

Hi all!
I'm developing an application to manage word templates and documents.
Documents are stored in database, so when user wants to edit a document
i make a local copy of this document and then open it through ms word.
I have handlers for beforeClose, beforeSave and Quit events. The
problem is following: i open any number of documents for editing, then
edit any document (say, document A) and don't save it (by ctrl+s, save
button e t.c.) and then close it (by alt+f4, close button) then my
application catch _only_ beforeClose event for document A (quit event
is not handled). For other opened documents application doesn't catch
any events at all. So now i can close all opened documents. After it i
can open documents again and _only now_ all event handlers work for
opened documents.

Here is the code i used

//adding handlers
....
app.DocumentBeforeClose += new
Microsoft.Office.Interop.Word.ApplicationEvents4_D ocumentBeforeCloseEventHandler(app_DocumentBeforeC lose);
app.DocumentBeforeSave += new
Microsoft.Office.Interop.Word.ApplicationEvents4_D ocumentBeforeSaveEventHandler(app_DocumentBeforeSa ve);
app.ApplicationEvents2_Event_Quit += new
Microsoft.Office.Interop.Word.ApplicationEvents2_Q uitEventHandler(app_ApplicationEvents2_Event_Quit) ;
.....

//handler for beforeClose event
private void
app_DocumentBeforeClose(Microsoft.Office.Interop.W ord.Document Doc, ref
bool Cancel)
{
//MessageBox.Show("Event BeforeClose");
//here i check if it is my application's
document or not
if (IsIMTemplate(Doc))
{
this.IMTemplateCheckedOut = false;
if (Doc.Saved)
{
this.imTemplateNeedUpdating = false;
}
else
{
DialogResult dialogResult;
//formDBC - just a form with 3
buttons Yes, No, Cancel
frmDialogBeforeClose formDBC = new frmDialogBeforeClose();
formDBC.TopMost = true;

formDBC.Focus();

dialogResult = formDBC.ShowDialog();

//do nothing
if (dialogResult == DialogResult.Cancel)
{//
Cancel = true;
this.IMTemplateCheckedOut = true;
}

//close documnet without updating it in database
if (dialogResult == DialogResult.No)
{
this.imTemplateNeedUpdating = false;
object saveChanges = false;
object optional = Missing.Value;
Word.ApplicationClass tmpApp = (Word.ApplicationClass)Doc.Parent;
Doc.Close(ref saveChanges, ref optional, ref optional);
tmpApp.Quit(ref saveChanges, ref optional, ref optional);
}

//close with updating in database
if (dialogResult == DialogResult.Yes)
{
this.imTemplateNeedUpdating = true;
Doc.Save();
}
formDBC.Dispose();
}//else
}
}

also i have handlers for other events but i think the problem somewhere
else...
Thnx in advance.

Apr 5 '06 #1
0 2156

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
5
by: Action | last post by:
does it works like ordinary virtual method?? coz I find that child class can't invoke the event of the parent class. class parent { public virtual event SomeDelegate SomeChanged; } class...
5
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
5
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.