标签:
private bool IsPost = false;
private int ColIndex = -1;
private void dgvMessage_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 40)//下
{
dgvMessage.Rows.Add();
ColIndex = dgvMessage.CurrentCellAddress.X;
IsPost = true;
}
else if (e.KeyValue == 38) //上
{
if (dgvMessage.Rows.Count > 1)
{
dgvMessage.Rows.RemoveAt(dgvMessage.Rows.Count - 1);
ColIndex = dgvMessage.CurrentCellAddress.X;
IsPost = true;
}
}
}
private void dgvMessage_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (IsPost)
{
this.dgvMessage.CurrentCell = this.dgvMessage.Rows[dgvMessage.Rows.Count - 1].Cells[ColIndex];
IsPost = false;
}
}
标签:
原文地址:http://www.cnblogs.com/gracexy/p/4725381.html