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.
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
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); }
Can't find what you're looking for? Ask the community or share your knowledge.