• asp.net datagridview按上下键添加删除行


             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;
                 }
            }

  • 相关阅读:
    如何提高沟通能力?
    如何做到科学决策?推荐你看这本《决策必读12篇》
    领导者如何让员工真心服从自己?
    MBA看什么书,MBA教材书目推荐
    有关战略管理的书,哪本最值得推荐?
    市场营销必看书籍推荐
    P1208 混合牛奶题解
    P5019 铺设道路题解
    P1728 陶陶摘苹果题解
    P1106 删数问题题解
  • 原文地址:https://www.cnblogs.com/gracexy/p/4725381.html
Copyright © 2020-2023  润新知