c# datagridview control
I add control to datagridview after doubleclick (rough code):
DoubleClick
{
datagridview.Controls.Add(newControl);
datagridview.ClearSelection(); //to be shure that any of cells are selected
newControl.Focus();
n开发者_如何学CewControl.KeyUp += new KeyEventHandler(newControl_KeyUp);
}
and:
newControl_KeyUp(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab || e.KeyCode == Keys.A)
{
Commit();
}
}
My new control reacts on Keys.A . but It doesn't react on tab and enter. When I click enter or tab, only datagridview selected cell changes.
Since Tab key make focus move, I will recommend you to work on a lower level if you can:
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
Control newControl = new MyTextBox();
dataGridView1.Controls.Add(newControl);
dataGridView1.ClearSelection(); //to be sure that any of cells are selected
newControl.Focus();
}
class MyTextBox : TextBox
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter || keyData == Keys.Tab || keyData == Keys.A)
{
Trace.WriteLine("Ok, key = " + keyData);
return true;///Or false??? return to override the basic behavior
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
精彩评论