避免例外 [英] Avoiding an exception

查看:118
本文介绍了避免例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行时在datagridview中创建行,并根据
将数据插入其中 检出的查询.
运行该程序后,它第一次运行良好.
因此,第二次执行查询后,我必须删除先前的行.
所以我在这里使用datagridview.Rows.Clear方法,但是不能抛出异常
清除这个.
那么如何将其删除..?
或者还有其他方法可以从datagridview中删除以前的行..?

I am creating the rows in datagridview at run time.And insert data into it according to
excuted query.
It works welll for first time after running the program.
So after executed query for second time i have to delete the previous rows.
So i am using there datagridview.Rows.Clear method but will throw an exception cannot
clear this.
So how to remove it..?
Or there is any other way to delete previous rows from datagridview..?

推荐答案

如果您已将datagrid绑定到数据源,则不能只是清除行.

您需要取消绑定(设置为null)网格中的数据源引用,或从数据源中删除行并重新绑定网格
If you''ve bound the datagrid to a datasource, you can''t just clear the rows.

You need to unbind (set to null) the datasource reference in the grid, or remove the rows from your datasource and rebind the grid


这篇关于避免例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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