怎么捕获DataGridView中列编辑模式中的按键事件
展开全部
继承DataGridView控件,然后写上:
public event KeyEventHandler CellKeyDown;
public event KeyEventHandler CellKeyUp;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool bResult;
if (CellKeyDown != null)
this.CellKeyDown(this, new KeyEventArgs(keyData));
if (msg.WParam.ToInt32() == (int)Keys.Return)
{
……
bResult = true;
}
else
bResult = base.ProcessCmdKey(ref msg, keyData);
if (CellKeyUp != null)
this.CellKeyUp(this, new KeyEventArgs(keyData));
return bResult;
}
public event KeyEventHandler CellKeyDown;
public event KeyEventHandler CellKeyUp;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool bResult;
if (CellKeyDown != null)
this.CellKeyDown(this, new KeyEventArgs(keyData));
if (msg.WParam.ToInt32() == (int)Keys.Return)
{
……
bResult = true;
}
else
bResult = base.ProcessCmdKey(ref msg, keyData);
if (CellKeyUp != null)
this.CellKeyUp(this, new KeyEventArgs(keyData));
return bResult;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询