I have my form's KeyPreview set to true.
I'm trying to move to the next cell down if a DataGridView cell already has a value. I've got this code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (this.ActiveControl == dataGridViewPlatypus)
{
var currentCell = dataGridViewPlatypus.CurrentCell;
if (currentCell.Value.ToString().Length == 1)
{
;//Now what?
SendKeys.Send("{DOWN}");
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
With a breakpoint set on the inner "if" I get there the first time I enter a value in a cell (presumably it is either length 0 or length 1, but looking at the value of currentCell at that point, it's "formatted text" value == "" and I don't see any other likely properties for discerning what the cell contents are).
The "if" fails, and it drops to the "return base." line.
When I enter a second value in the cell (what is visible in the cell changes from "2" to "22" for example), I don't even reach the breakpoint. Why???
Note: This is a variation on a question I asked here: How can I programmatically move from one cell in a datagridview to another?