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

查看:1706
本文介绍了VB.NET:清除DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了 -

  DataGridView1.DataSource = Nothing 

  DataGridView1.DataSource = Nothing 
DataGridView1.Refresh()

  DataGridView1.RefreshEdit()

/ p>

我写了一个方法来设置DataGridView的DataSource在执行时。但是每次执行它时,它会将数据复制到新的值中,并将其附加到DGV的前一个内容中。我想要清除内容,然后添加值..这是可能吗?

解决方案

如果DataGridView绑定到任何数据源,则必须将DataGridView的 DataSource 属性设置为

如果DataGridView没有绑定到任何数据源,这个代码将会做到这一点: p>

  DataGridView.Rows.Clear()


I've tried -

DataGridView1.DataSource=Nothing

and

DataGridView1.DataSource=Nothing
DataGridView1.Refresh()

and

DataGridView1.RefreshEdit()

None of them works..

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?

解决方案

If the DataGridView is bound to any datasource, you'll have to set the DataGridView's DataSource property to Nothing.

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天全站免登陆