隐藏DataGridView的数据行时一个异常的处理

在对DataGridView编程的时候,需要隐藏其中的某些行。采用:

this.dataGridView1.Rows[i].Visible = false;

就可以达到隐藏数据行的目的。但有时候会报以下的错误:

Row associated with the currency manager's position cannot be made invisible.

其原因是,dataGridView1CurrentCell所在的行是不能删除的。因此,在隐藏列之前只需要将CurrentCell指向其他行的Cell就可以了。示例代码:

dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];

this.dataGridView1.Rows[0].Visible = false;

原文地址:https://www.cnblogs.com/qkhh/p/1522088.html