如何清除数据网格视图 [英] How to clear a data grid view
本文介绍了如何清除数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要填充基于在组合框中选择的项目,我有这部分工作的一个DataGridView。
I am trying to populate a DataGridView based on the selected item in a ComboBox, I have this part working.
不过,我需要能够清除从一个新的项添加新的数据,而不是它只是添加到结束前网格。
However, I need to be able to clear the grid before adding the new data from a new item rather than it just adding on to the end.
如何将项目添加到它之前清除一个DataGridView?
推荐答案
首先,空数据源:
this.dataGridView.DataSource = null;
然后清除行:
Then clear the rows:
this.dataGridView.Rows.Clear();
然后设置数据源到新的列表:
Then set the data source to the new list:
this.dataGridView.DataSource = this.GetNewValues();
这篇关于如何清除数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文