ETA:我想可能会关闭MultiSelect并将选择模式更改为CellSelect,然后为RowheaderMouseClick事件添加事件处理程序将起作用… nope.
解决方法 我想出如何实现这一点的最好方法是从DataGrIDVIEw继承并重写ProcessCmdKey方法.然后你可以拦截Shift Space并发送Space.只需将此类添加到项目中,并将所有DataGrIDVIEws切换到MyDataGrIDVIEws.我的解决方案从这个 DataGridView keydown event not working in C# SO问题(这也解释了为什么Zaggler的解决方案不起作用)和 SendKeys in ProcessCmdKey: change Shift-Space to just a Space Bytes.com帖子中汲取灵感.对不起,但它在C#中.class MyDataGrIDVIEw : System.windows.Forms.DataGrIDVIEw{ protected overrIDe bool ProcessCmdKey(ref System.windows.Forms.Message msg,System.windows.Forms.Keys keyData) { if (keyData == (System.windows.Forms.Keys.Space | System.windows.Forms.Keys.Shift)) { // DataGrIDVIEw is dumb and will select a row when the user types Shift+Space // if you have the DGV set so that you can click a row header to select a row (for example,to delete the row) // this method will intercept Shift+Space and just send on Space so that the DGV properly handles this. // For example,if I type "ME TYPing IN ALL CAPS" it ends up looking like "METYPingINALLCAPS". // Or if I type "Note: I have some OS thing to talk about" it looks like "Note:Ihave some OSthing to talk about" byte[] keyStates = new byte[255]; UnsafeNativeMethods.GetKeyboardState(keyStates); byte shiftKeyState = keyStates[16]; keyStates[16] = 0; // turn off the shift key UnsafeNativeMethods.SetKeyboardState(keyStates); System.windows.Forms.SendKeys.SenDWait(" "); keyStates[16] = shiftKeyState; // turn the shift key back on UnsafeNativeMethods.SetKeyboardState(keyStates); return true; } return base.ProcessCmdKey(ref msg,keyData); } [System.Security.SuppressUnmanagedCodeSecurity] internal static class UnsafeNativeMethods { [System.Runtime.InteropServices.Dllimport("user32.dll",CharSet = System.Runtime.InteropServices.CharSet.auto)] public static extern int GetKeyboardState(byte[] keystate); [System.Runtime.InteropServices.Dllimport("user32.dll",CharSet = System.Runtime.InteropServices.CharSet.auto)] public static extern int SetKeyboardState(byte[] keystate); }}总结
以上是内存溢出为你收集整理的vb.net – 覆盖DataGridView Shift Space全部内容,希望文章能够帮你解决vb.net – 覆盖DataGridView Shift Space所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)