Cancelling Events with AddAdvise / Undo

D

Daniel Shookowsky

I'm using the AxDrawingControl provided with Visio 2003 professional in a
..NET application. I just created an Event sink for Visio using
AddAdvise/IVisEventProc, but unfortunately, I've just discovered that
returning false from this method does not have the desired effect of
cancelling the event. (Closer inspection of the documentation shows that
this only works for Query* events.)

When the Visio is updated, I'd like to checkout the document. If the
checkout fails, I don't want the change to persist on screen.

I've tried the Undo method of the application, but this consistently
throws an Exception with the almost, but not quite entirely, useless
message "An exception occurred"

The entire point of replacing the standard events with AddAdvise-raised
events was to provide a single location where checkout and
undo/event-suppression could occur.

I know that it may be possible to load the Visio document into some type
of viewer control, but the application is largely complete minus this
feature and I'd prefer not having to made such a large change at this
point in the development cycle.
 
T

Tony Burke

The only way I know to unsubscribe to an Event is by calling the
Event.Delete() method.
 
D

Daniel Shookowsky

Perhaps you misunderstand what I'm trying to accomplish (or perhaps I
misunderstand your response).


In my application, the user is presented with a Visio drawing control
with multiple pages. I'd like to prevent the user from making changes to
the Visio document until the vsd file has been checked out of source
control. Visio itself allows you to randomly change a diagram even if it's
read-only, and this is not the behavior that I want.


My first thought was to trap the events and cancel them if the checkout
fails. That didn't work because I couldn't cancel the events, or undo the
operation. I've tried to place all of the shapes on a locked layer, but
this doesn't stop users from adding new shapes. I've disabled my
Usercontrol containing the AxDrawingControl, but this has the side effect
of preventing the user from switching pages as well.

If Undo worked at all programmatically, I think that my problems would be
solved. I haven't had any success up to this point however.
 
T

Tony Burke

Yep, you're right, I did misunderstand your issue.

It's possible the problem with the Application.Undo() may have something to
do with the Application.CurrentScope unit being unfinished (just a guess).

Although, you should be able to create an outer unit using
Application.BeginUndoScope and undo that unit once all nested units are
finished. You could keep track of the inner units by watching the
EnterScope/ExitScope events and once all innter are complete, perform the
undo on your unit.

This way, you could create your own ReadOnly flag that (once set) would
start an undo unit and watch for anything to change via the events. When a
unit that modifies the document is complete, perform your undo (probably
during a visEvtNonePending event) and re-start your unit for the next time.

Just a thought.... hope that helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top