.NET

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

Datagridview in palette -'ESC' key problem

281 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,
G
ADN Support Specialist
Balaji_Ram
Posts: 667
Registered: ‎03-21-2011
Message 2 of 2 (265 Views)

Re: Datagridview in palette -'ESC' key problem

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

Hello,

 

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)
					{
						_uc.DataGridView1.CancelEdit();
					}
				}
			}
			return false;
		}
	}

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

		static private MyUserControl _uc;

		[CommandMethod("ShowPalette")]
		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();
			_filter.SetUserControl(_uc);
			System.Windows.Forms.Application.AddMessageFilter(_filter);
		}

		private void IExtensionApplication_Terminate()
		{
			System.Windows.Forms.Application.RemoveMessageFilter(_filter);
		}

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community