如何在c#中清除datagridview [英] how to clear datagridview in c#

查看:113
本文介绍了如何在c#中清除datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中清除datagridview

解决方案

当你想清除时使用此代码



 gridView1.DataSource =  null ; 
gridView1.DataBind();


你没有清除网格,你清除数据



 DataGridView.DataSource =  null ; 


< blockquote>试试这个:



 dataGridView1.Rows.Clear()



< b> OR

 dt.Rows.Clear()//如果dgv绑定到datatable 
dataGridView1.DataBind();









使用此代码检查您是否绑定到数据源:



 //代码块
if(this.dataGridView1.DataSource!= null)
{
this.dataGridView1.DataSource = null;
}
其他
{
this.dataGridView1.Rows.Clear();
}


how to clear datagridview in c#

解决方案

Use This Code When U want to clear

gridView1.DataSource = null;
gridView1.DataBind();


You don't clear the grid, you clear the data

DataGridView.DataSource = null;


Try this :

dataGridView1.Rows.Clear()


OR

dt.Rows.Clear() // If dgv is bound to datatable
dataGridView1.DataBind();



OR

Use this code to check if you are bound to a data source :

//Code Block
if (this.dataGridView1.DataSource != null)
{
     this.dataGridView1.DataSource = null;
}
else
{
    this.dataGridView1.Rows.Clear();
}


这篇关于如何在c#中清除datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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