<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Datagridview in palette -'ESC' key problem in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/datagridview-in-palette-esc-key-problem/m-p/3467030#M55496</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen some keys that&amp;nbsp;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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 &lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://forums.autodesk.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the sample code for the workaround&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	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 &amp;amp; System.Windows.Forms.Keys.KeyCode;
				if (m.Msg == WM_KEYDOWN &amp;amp;&amp;amp; kc == System.Windows.Forms.Keys.Escape)
				{
					if (_uc.DataGridView1 != null &amp;amp;&amp;amp; _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);
		}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 May 2012 12:08:37 GMT</pubDate>
    <dc:creator>Balaji_Ram</dc:creator>
    <dc:date>2012-05-22T12:08:37Z</dc:date>
    <item>
      <title>Datagridview in palette -'ESC' key problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/datagridview-in-palette-esc-key-problem/m-p/3466730#M55495</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I placed a datagridview on my toolpalette.&lt;BR /&gt;Normaly when we press 'esc' key while we are editing in the cell, cell value restore to original.&lt;BR /&gt;But in my palette, the cell do not get original value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i placed on separate 'windows application', it works perfect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where i am wrong?&lt;BR /&gt;Anybody face the same issue?&lt;/P&gt;&lt;P&gt;Any hint will help me lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using VisualStudio.net 2008, .net framework 3.5SP1,AutoCAD2011.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for looking.&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2012 03:00:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datagridview-in-palette-esc-key-problem/m-p/3466730#M55495</guid>
      <dc:creator>ProfWolfMan</dc:creator>
      <dc:date>2012-05-22T03:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Datagridview in palette -'ESC' key problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/datagridview-in-palette-esc-key-problem/m-p/3467030#M55496</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen some keys that&amp;nbsp;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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 &lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://forums.autodesk.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the sample code for the workaround&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	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 &amp;amp; System.Windows.Forms.Keys.KeyCode;
				if (m.Msg == WM_KEYDOWN &amp;amp;&amp;amp; kc == System.Windows.Forms.Keys.Escape)
				{
					if (_uc.DataGridView1 != null &amp;amp;&amp;amp; _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);
		}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2012 12:08:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datagridview-in-palette-esc-key-problem/m-p/3467030#M55496</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2012-05-22T12:08:37Z</dc:date>
    </item>
  </channel>
</rss>

