如何在vb.net中将焦点放在Datagridview的特定单元格上 [英] how to set focus on a particular cell of Datagridview in vb.net

查看:255
本文介绍了如何在vb.net中将焦点放在Datagridview的特定单元格上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
如何将焦点放在datagridview的特定单元格上.实际上我想跳过
一个单元格(紧邻下一列的单元格).
我做了这样的事情.


Hi all,
How to set focus on a particular cell of datagridview..Actually i want to skip
a cell(immediate next column''s cell).
I did something like this..


grdJV.CurrentCell = grdJV(e.rowindex, e.columnindex+2)



异常是类型为system.stackOverflowexception



Excepition is An unhandled exception of type system.stackOverflowexception

推荐答案

焦点"是该概念的简称,也称为键盘焦点".它仅与键盘有关;其他所有内容只是控件具有焦点的视觉反馈.它仅归因于控件,没有别的.因此,不存在聚焦单元"之类的东西,因为单元不是控件,而只是控件的一部分.只有整个DataGridView可以被聚焦.只能选择一个单元格,但它也取决于选择模式.请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/3c89df86.aspx [ ^ ].

考虑到这一点,如何以编程方式选择一个单元?有一个属性可以做到这一点:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.selected.aspx [ ^ ].

最后,堆栈溢出异常如何?请参阅我对问题的评论-您未显示相关代码.不用担心:此异常是最容易检测到的异常之一.最有可能(几乎100%的情况)是无限" 递归相互递归的结果:
http://en.wikipedia.org/wiki/Recursion [ http://en.wikipedia.org/wiki/Mutual_recursion [
—SA
"Focus" is a shorter name for the concept also called "keyboard focus". It''s related to keyboard only; everything else is just the visual feedback that a control has focus. And it is attributed only to controls, nothing else. So, there is no such thing as "focused cell", because a cell is not a control, only a part of it. Only the whole DataGridView can be focused. A cell can only be selected, but it also depends on selection mode. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode.aspx[^],
http://msdn.microsoft.com/en-us/library/3c89df86.aspx[^].

Having this in mind, how to select a cell programmatically? There is a property to do that:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.selected.aspx[^].

Finally, how about stack overflow exception? Please see my comment to the question — you did not show relevant code. Not to worry: this exception is one of the easiest for detection. Most likely (nearly 100% of cases), this is a result of "infinite" recursion or mutual recursion:
http://en.wikipedia.org/wiki/Recursion[^],
http://en.wikipedia.org/wiki/Mutual_recursion[^].

Put a break point on this line and run it under debugger. Make sure it throws the exception (disable the break point temporarily) and execute the code again to come to the same point. Try to step into under debugger. Eventually, you will be stopped at the same point. Through debugging, figure out why. Moreover, if you can stop at the point of code where execution brings you repetitively, open the debug window "Call Stack" — you will see where the chain of calls goes. If will help you to fix the problem in no time. It''s also good to learn how stack works anyway.

—SA


这篇关于如何在vb.net中将焦点放在Datagridview的特定单元格上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆