Winform 删除DataGridView指定行后所有行

 private void skinDataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 0 || e.RowIndex < 0) return;
            if (skinDataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == "结束")//如果当前行0列为“结束”
            {
                skinDataGridView1.AllowUserToAddRows = false;//则自动增加行为false

                for (int i = e.RowIndex+1 ; i < skinDataGridView1.Rows.Count; i++)//删除“结束”行后所有行
                {
                    DataGridViewRow row = skinDataGridView1.Rows[i];
                    skinDataGridView1.Rows.Remove(row);
                    i--;//关键中的关键
                }
            }
            else//否则
            {
                if(e.RowIndex== skinDataGridView1.Rows.Count-1)//如果当前点击行为表格的最后一行
                skinDataGridView1.AllowUserToAddRows = true;//则打开自动增加行功能
            }

自己写软件的一些笔记,大神请忽略!

posted @ 2021-08-04 11:24  Cmale  阅读(232)  评论(0编辑  收藏  举报