Trouble with DeselectAll()

L

LarryF

I'm sure I'm missing something obvious, but I'm stumped.
Window.SelectAll() works fine for me, but Window.DeselectAll() seems to
do nothing at all.

I'm running a Visio 2003 SP2 DrawingControl in a C# form. My test
program has three buttons, one each for drawing, selecting, and
deselecting. Here's a code snippet:

private AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl dc;
private void btnDraw_Click(object sender, System.EventArgs e) {
dc.Document.Pages[1].DrawRectangle(3, 3, 5, 5);
dc.Document.Pages[1].DrawRectangle(4, 4, 6, 6);
}

private void btnSelect_Click(object sender, System.EventArgs e) {
dc.Window.SelectAll();
}

private void btnDeselect_Click(object sender, System.EventArgs e) {
dc.Window.DeselectAll();
}

'dc' is the drawing control, which I added by dragging 'Microsoft Visio
11.0 Drawing Control' from the toolbox onto a form. When you click
btnDraw, it draws two rectangles. When you click btnSelect, it selects
them both. When you click btnDeselect, it executes the
dc.Window.DeselectAll(), but the two shapes are still selected.

In a NoEventsPending event handler in my full application, I can make a
call to DeselectAll () throw a 'Requested operation is presently
disabled' exception, and a call to Select() can throw 'Invalid window
type for this action' exception, after drawing, grouping, and deleting
several shapes. So I wrote the simple test app.

Can one of you mavens please point out glaringly obvious reason that
DeselectAll() won't work for me?

Thanks
 
J

JuneTheSecond

Please try
dc.Window.Application.Activewindow.SelectAll();
dc.Window.Application.Activewindow.DeselectAll();

or
dc.Document.Application.Activewindow.SelectAll();
dc.Document.Application.Activewindow.DeselectAll();
 
L

LarryF

JuneTheSecond said:
Please try
dc.Window.Application.Activewindow.SelectAll();
dc.Window.Application.Activewindow.DeselectAll();

or
dc.Document.Application.Activewindow.SelectAll();
dc.Document.Application.Activewindow.DeselectAll();

Thanks for the reply. I tried both ways, with appropriate
caplitalization. The SelectAll() still works correctly. The
DeselectAll() still executes without throwing any exceptions, but the
shapes remain selected. In other words, there is no change from
dc.Window.DeselectAll().

Any other ideas for me to try?

Thanks.
 
J

JuneTheSecond

How about DoCmd?
dc.Window.Application.DoCmd(1213);
1213 means visCmdDeselectAll.
 
L

LarryF

JuneTheSecond said:
How about DoCmd?
dc.Window.Application.DoCmd(1213);

DoCmd(1213) behaves exactly like calling DeselectAll(), meaning that it
doesn nothing at all in my event handler.

I've found that calling DeselectAll() twice in a row does work, meaning
that the first call does nothing but the second call does what it is
supposed to. Calling DoCmd(1213) twice also works. This is not a good
work-around for me because the real problem involves exceptions being
thrown is certain cases.

So I reinstalled Visual Studio 2003 and Visio 2003. Same problem. Then
I got a different computer with a clean install of Windows XP and
installed VS 2003 and Visio 2003. Same problem.

I think my problem is related to event handling. Calling DeselectAll
from an event handler seems to be what is broken. Calling it twice in
the same event handler works, but calling it once each in two
subsequent event handlers fails. Using Selection.DeselectAll() works
wrong just like Window.DeselectAll().

Why doesn't this work for me:
- Create a new Visual Studio C# project.
- Add a drawing control and two buttons named Draw and Deselect.
- In the event handler for the Draw button, put:
dc.Document.Pages[1].DrawRectangle(2, 2, 4, 4);
- In the event handler for the Deselect button, put:
dc.Document.Application.Window.DeselectAll();

Run the project and click the Draw button. It draws a square and
selects it so you see the eight green resize handles around it. Click
the Deselect button. The shape is still selected. Why is it still
selected?

Thanks for any help you can give me.
 
P

Paul Herber

DoCmd(1213) behaves exactly like calling DeselectAll(), meaning that it
doesn nothing at all in my event handler.

I've found that calling DeselectAll() twice in a row does work, meaning
that the first call does nothing but the second call does what it is
supposed to. Calling DoCmd(1213) twice also works. This is not a good
work-around for me because the real problem involves exceptions being
thrown is certain cases.

Have you tried forcing a screen update after the first call to
DeselectAll?
 
L

LarryF

Paul said:
Have you tried forcing a screen update after the first call to
DeselectAll?

Interesting idea. I tried System.Windows.Forms.Application.DoEvents().
No change. Neither did minimizing and restoring the window. Neither did
Ctrl+Alt+G. Neither did playing with
dc.Window.Application.ScreenUpdating.

Then I tried dc.Window.ShowChanges. Guess what? If turn off ShowChanges
before calling DeselectAll() in an event handler, it works, as in:
dc.Document.Application.ShowChanges = false;
dc.Document.Application.Window.DeselectAll();
dc.Document.Application.ShowChanges = true;

I still have no idea why, but it seems to work. Thanks to Paul and
everyone else.

Larry
 

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