VB.NET-Grid 双击在单击时触发
好的,这是一个奇怪的 VB.NET 网格问题。我确信这确实很简单,但对我来说没有意义。
我有一个显示来自绑定源的数据的网格。我有一个方法来处理 CellContentDoubleClick ,它将获取单元格的值并使用它来进行新的查找。这将生成一个新的数据源(具有不同的列),然后我将其重新绑定到网格。
我的网格双击有效,但是当它使用新数据重新绘制时,单击会触发双击。无论是否有单击处理程序,都会发生这种情况。
有趣的是,它(就我而言)是一个切换开关。如果我在重绘上双击,则单击会触发双击代码。当它再次重新绘制时,我需要双击。
双击代码会触发一个消息框 - 如果我告诉它不要继续,那么我必须双击才能再次触发它。所以它不依赖于显示什么数据。
当它处于响应单击模式时,我可以通过选项卡浏览所有控件,然后单击网格中的任何单元格,它仍然会触发双击。
无论我尝试做什么(将焦点设置到其他控件、刷新网格等),似乎都没有重置网格,因此它可以一致地工作。
有什么想法吗?
Ok, here is a weird VB.NET Grid problem. I am sure it is really simple, but it doesn't make sense to me.
I have a grid that displays data from a binding source. I have a method to handle the CellContentDoubleClick which will get the value of the cell and use that to do a new look up. This will generate a new datasource (with different columns) which I then rebind to the grid.
My grid double click works, but when it repaints with the new data, a single click fires the double click. This happens whether or not thre is a single click handler.
The interesting thing is that it is (in my case) a toggle. If I double click, on the repaint, a single click fires the double click code. When it repaints again, I need a double click.
The double click code fires off a messagebox - if I tell it not to continue, then I have to double click to get it to fire again. So it is not dependant on what data is displayed.
When it is in the mode to respond to a single click, I can tab through all the controls and then click on any cell in the grid and it will still fire the double click.
No matter what I try to do (set focus to other controls, refresh the grid, etc.) nothing seems to reset the grid so it works consistently.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了答案。数据网格(至少在 VS.Net 2007 中)有一个名为“EditMode”的属性。如果将其设置为 EditOnEnter(不是默认值),那么您将遇到此行为。如果您重置它(或将其更改为 EditOnKeyStrokeOrF2),那么数据网格将按您的预期工作(没有像双击一样的单击。)
这是在使用线程、子类网格进行测试之后,您能想到的......我应该回顾一下首先属性设置......抱怨......
Ok, I found the answer. The data grid (at least in VS.Net 2007) has a property named "EditMode". If that is set to EditOnEnter (NOT the default) then you will experience this behavior. If you reset it (or change it to EditOnKeystrokeOrF2) then the datagrid will work as you expect (no single clicks acting like double clicks.)
This is after testing with threads, subclassed grids, you name it... I should have reviewed the property settings first.... grumble....