Valued Contributor
Posts: 86
Registered: ‎04-21-2010
Message 1 of 2 (312 Views)

Datagridview in palette -'ESC' key problem

312 Views, 1 Replies
05-21-2012 08:00 PM

Hi all,


I placed a datagridview on my toolpalette.
Normaly when we press 'esc' key while we are editing in the cell, cell value restore to original.
But in my palette, the cell do not get original value.


If i placed on separate 'windows application', it works perfect.


Where i am wrong?
Anybody face the same issue?

Any hint will help me lot.


I am using VisualStudio.net 2008, .net framework 3.5SP1,AutoCAD2011.


Thanks for looking.

Thanks & Regards,
ADN Support Specialist
Posts: 733
Registered: ‎03-21-2011
Message 2 of 2 (296 Views)

Re: Datagridview in palette -'ESC' key problem

05-22-2012 05:08 AM in reply to: ProfWolfMan



I have seen some keys that do not work with controls placed in the palette and I think it is because the palette does not pass them to the controls for appropriate handling.


A possible workaround could be to use the "KeyMessageFilter" to handle the escape key press and then pass it on to the data grid for cancelling the edit.


Here is the sample code, but it requires a bit more fine tuning. I have made the datagrid control as public to get easy access. I know its not neat :smileytongue:


Here is the sample code for the workaround :


	class KeyMessageFilter : System.Windows.Forms.IMessageFilter
		private const int WM_KEYDOWN = 0x100;
		static private MyUserControl _uc;

		public void SetUserControl(MyUserControl uc)
			_uc = uc;

		bool System.Windows.Forms.IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message m)
			if (m.Msg == WM_KEYDOWN)
				Document doc = Application.DocumentManager.MdiActiveDocument;
				Editor ed = doc.Editor;

				// Check for the Escape keypress

				System.Windows.Forms.Keys kc = (System.Windows.Forms.Keys)(int)m.WParam & System.Windows.Forms.Keys.KeyCode;
				if (m.Msg == WM_KEYDOWN && kc == System.Windows.Forms.Keys.Escape)
					if (_uc.DataGridView1 != null && _uc.DataGridView1.IsCurrentCellInEditMode)
			return false;

	public class MyCommands : Autodesk.AutoCAD.Runtime.IExtensionApplication
		private KeyMessageFilter _filter;
		static Autodesk.AutoCAD.Windows.PaletteSet _palette;

		static private MyUserControl _uc;

		public void ShowPalette()
			if (_palette == null)
				_palette = new Autodesk.AutoCAD.Windows.PaletteSet("PaletteCmd", new Guid("{95BC5096-54DA-408a-836B-8969145A4F85}"));
				_palette.Style = PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton | PaletteSetStyles.Notify | PaletteSetStyles.Snappable;
				_palette.Text = "Test";
				_palette.Add(null, _uc);
			_palette.Visible = true;

		private void IExtensionApplication_Initialize()
			Document activeDoc = Application.DocumentManager.MdiActiveDocument;
			Database db = activeDoc.Database;
			Editor ed = activeDoc.Editor;
			_uc = new MyUserControl();
			_filter = new KeyMessageFilter();

		private void IExtensionApplication_Terminate()





Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!