Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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)


Excepition is An unhandled exception of type system.stackOverflowexception
Posted
Updated 21-Oct-12 23:14pm
v2
Comments
Sergey Alexandrovich Kryukov 22-Oct-12 16:46pm    
Definition of rgdJV, please. It looks like you have two entities under this name: some object and some method. Definitions, please.
Due to current foliage season, my access to your hard drive is somewhat limited.
--SA

1 solution

"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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900