Monitoring the count of the Selection object

V

visi3d

I am trying to find an event that will fire when the number of items i
the active window's selection object changes. I had hoped that this wa
the purpose of visEvtCodeWinSelChange, but it does not seem to be th
case.

So two questions if you please.

1) What exactly WILL trigger visEvtCodeWinSelChange?

2) Is there an event(s) that can be used to track when the selectio
object's count is greater than 0?

The ultimate goal is to disable a context menu item that is useles
without shapes in the selection.

Thanks in advance
 
A

Al Edlund

When the selections changes the event fires... This can be because something
was either selected, or, de-selected (i.e. collection count is zero).
What you might consider doing is when the selection change event fires,
capture the event and get a count from the collection before doing anything
(which is what I do).
al
 
V

visi3d

Thanks for replying. I opened the Visio Event Monitor that came with th
SDK and tested when it fires and it behaves as I would expect. However
my code does not catch any of the events nor does it give me any error


-----------------------------------------------------------------

EventSink sink = new EventSink();
EventList events = VisApp.EventList;

events.AddAdvise(((short)VisEventCodes.visEvtCodeOpen), sink, "", "");
events.AddAdvise(((short)VisEventCodes.visEvtCodeWinSelChange), sink
"", "");

------------------------------------------------------------------


In my EventSink class..


------------------------------------------------------------------

public object VisEventProc(short eventCode, object source, int eventId
int eventSequenceNumber, object subject, object moreInformation)
{
Document subjectDocument = (Document)subject;
Application VisApp = subjectDocument.Application;
switch (eventCode)
{
case (short)VisEventCodes.visEvtCodeDocCreate:
case (short)VisEventCodes.visEvtCodeDocOpen:
DoFunctionA();
break;
case (short)VisEventCodes.visEvtCodeWinSelChange:
DoFunctionB();
break;
}
return false;
}

--------------------------------------------------------

Now, the document-open event gets caught but the selection change doe
not. I'm lost. What am I missing?

Please and thanks
 
A

Al Edlund

I'm no expert but the code you have shown looks good. What is in functionB
that you use to show that it works? Have you considered a.) putting a msg
prompt in place of the function to get a more immediate feedback b.) put a
msg prompt at the beginning of the case routine to view all of the events
that come in, to see if one ever arrives
al
 
V

visi3d

Thanks Al,

Yeah, those functions are essentially stubs.. inside each is
debug.write. DoFunctionA also is adding an context menu item. But
have a debug breakpoint on the "switch(eventCode)" line anyway and i
never reaches there.

In stepping through the code it seems to add the event advisor(?) t
the EventList. No errors. The correct event code (701) appears in m
watch window.

I certainly don't get it
 
V

visi3d

Mystery solved Al..

One of those case where you keep overlooking something obvious.

I was converting the source object to a document object (it was a
Application object) and this exiting the code in error. Moving th
following code into the Case for which it was intended (rather tha
before the Switch executed) fixed the issue.

Document subjectDocument = (Document)subject;
Application VisApp = subjectDocument.Application;

Thank
 
A

Al Edlund

If you can see the event code being posted to the handler, (the assumption
is you have a break just before the case process begins in the handler), and
do not see it in your stub you might try two scenarios.
a.) first put a break between the case selection and the stub to see if the
case logic is working
b.) change the visevt coding in the case selection to a numeric 701 (if you
see it in the beginning of the event processor and don't see it in the case
selection then it's a VS issue not a Visio issue).
al
 

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