"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