.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PaletteSet Focus Issues with DataGridView

8 REPLIES 8
Reply
Message 1 of 9
xeri0n
748 Views, 8 Replies

PaletteSet Focus Issues with DataGridView

Hello all,

 

PaletteSet and focus issues are nothing new but I've never had any issues up to now.

Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView() seemed to always do the job for me.

 

However, I have now placed a datagrid view in a PaletteSet and things got a bit tricky.

There is no way that I can pass Focus to my drawing from the datagridview. Everything else works fine.

 

Things I have tried include pInvoke calls to :

SetForegroundWindow(IntPtr hWnd);

SetActiveWindow(IntPtr hWnd);

SetForegroundWindow(IntPtr hWnd);

 

PostMessage(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
System.Windows.Forms.Application.DoEvents();

 

Unless I am doing something wrong none of the above has worked.

I am attaching a minimal working example of the above issue with the hope that someone can shed some light...

 

Thanks in advance.

8 REPLIES 8
Message 2 of 9
Nilin123
in reply to: xeri0n

        /// <summary>
        /// Sets the focus on Acad Main window
        /// </summary>
        /// <param name="hwnd"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        private extern static System.IntPtr SetFocus(System.IntPtr hwnd);

        public static void FocusMainWindow()
        {
            SetFocus(Application.MainWindow.Handle);
        }

 Ever tried something like this ?

Message 3 of 9
xeri0n
in reply to: xeri0n

Indeed I did try to set the Focus as well. I just forgot to post it here

 

[DllImport("user32.dll")]
static extern IntPtr SetFocus(IntPtr hWnd);

[DllImport("user32.dll")]
static extern bool SetActiveWindow(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
private const int WM_SETFOCUS = 7;
PostMessage(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Document.Window.Handle, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
System.Windows.Forms.Application.DoEvents();

 

I tried all of the above pInvoke Calls with no success.

 

Message 4 of 9
Nilin123
in reply to: xeri0n

This really seems very strange, ...

The only advise I have is to try this project in WPF instead of Windowsforms or to use an alternate control instead of the Datagrid.

Message 5 of 9
Balaji_Ram
in reply to: xeri0n

Hi,

 

I could reproduce the behavior and have logged a request in our internal database for our engineering team to analyze. 

 

Sorry, I have not found an elegant workaround for it.

 

A way to overcome this behavior is to create a command that prompts for the point input  and have the command invoked using a "SendStringToExecute". The focus can be set to the AutoCAD editor just before invoking the custom command. Please note that the command invocation is asynchronous and this will need to be considered while further processing the point input.



Balaji
Developer Technical Services
Autodesk Developer Network

Message 6 of 9
xeri0n
in reply to: Balaji_Ram

Hi,

The Asynchronous is not an issue since you can always call acedPostCommand which is syncrhonous.
The problem though is how will you know the users selection, for example if its just a point.
Commands can not return not take any varialbes as parameters.

The command class is instastantiated by Autocad so unless there is a way to get a reference to that there is no way to get the user selection.

Am I missing something cause I dont think that this work arround will work.

Message 7 of 9
Balaji_Ram
in reply to: xeri0n

Hi,

 

Not all calls to acedPostCommand or SendCommand run synchronously, escpecially considering that the call is from a modeless dialog. Also it is not possible to use acedCmd from code that runs in session context.

http://adndevblog.typepad.com/autocad/2013/01/execute-commands-from-a-modeless-dialog.html

 

Yes, I agree that we cannot directly get the command method to return the selected point value. But if the command method gets access to your user control, it can call a method in it after the selection is done. You can also setup a delegate that the command method can use to pass-on the selected point to the user control.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 8 of 9
xeri0n
in reply to: Balaji_Ram

Hi,

 

But that is exactly the problem, how to get access to my control since MyCommands class for example is instantiated by Autocad.

That means that unless I can get a reference somehow to that class I wont be able to set up a delegate or pass a reference to my control in order to call a function of my control class.

 

Thanks in advance

Message 9 of 9
Matti72
in reply to: xeri0n

I had a similiar problem...

 

I helped myself by adding a static delegate to the Command Class.

 

So I can set up the static delegate which the function I want to call after the selection... then I call the Command and the command looks for the static delegate....

 

Something like this:

 

static public ContinueAfterSelectDelegate _InternerDummySelectContinueDelegate; 

 

and in the Command:

 

ss = editor.GetSelection(sOpt);
if (ss.Status == PromptStatus.OK)
{.

...

if (_InternerDummySelectContinueDelegate != null)
_InternerDummySelectContinueDelegate(result, pickPt);

}

 

works fine for me... 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost