VB.NET:清除 DataGridView [英] VB.NET: Clear DataGridView

查看:51
本文介绍了VB.NET:清除 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆