第一种:dataGridView.DataSource = null;
第二种: while (this.dataGridView.Rows.Count != 0)
{
this.dataGridView.Rows.RemoveAt(0);
}
本文介绍两种有效的方法来清空DataGridView中的所有数据。第一种方法通过设置DataGridView的数据源为null实现;第二种方法采用循环移除每一行的方式进行。这两种方法各有特点,适用于不同的应用场景。
第一种:dataGridView.DataSource = null;
第二种: while (this.dataGridView.Rows.Count != 0)
{
this.dataGridView.Rows.RemoveAt(0);
}
6238

被折叠的 条评论
为什么被折叠?