VB.NET:清除 DataGridView [英] VB.NET: Clear DataGridView
问题描述
我试过了 -
DataGridView1.DataSource=Nothing
和
DataGridView1.DataSource=Nothing
DataGridView1.Refresh()
和
DataGridView1.RefreshEdit()
它们都不起作用..
我编写了一个方法,用于在执行时设置 DataGridView 的数据源.但是每次我执行它时,它都会用新值复制数据并将其附加到 DGV 的先前内容中.. 我想清除内容然后添加值.. 这可能吗?
I've written a method that sets the DataSource of the DataGridView when executed. but each time i execute it, it replicates the data with new value and appends it to the previous contents of the DGV.. I wanna clear the content and then add the values.. Is that possible?
推荐答案
如果 DataGridView 绑定到任何数据源,则必须将 DataGridView 的 DataSource
属性设置为 Nothing代码>.
If the DataGridView is bound to any datasource, you'll have to set the DataGridView's DataSource
property to Nothing
.
如果 DataGridView 未绑定到任何数据源,则此代码将起作用:
If the DataGridView is not bound to any data source, this code will do the trick:
DataGridView.Rows.Clear()
这篇关于VB.NET:清除 DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!