正确的方法,从一个DataGridView取消绑定的BindingSource [英] Correct way to unbind a BindingSource from a DataGridView

查看:240
本文介绍了正确的方法,从一个DataGridView取消绑定的BindingSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的BindingList<对象>设置为的BindingSource的数据源。
此设置为DataGridView的数据源。

I have a BindingList<> of objects, set to the DataSource of a BindingSource. This is set to the DataSource of a DataGridView.

我很担心没有造成任何潜在的内存泄漏,所以不知道是否有一个最佳途径。当我与数据完成解除这些连接

I'm concerned with not causing any potential memory leaks, so wondering if there is a preferred way to unbind these connections when I am finished with the data.

我在想:

datagridview.DataSource = null;
bindingsource.DataSource = null;
bindingsource.Clear();

要重新绑定:

bindingsource.DataSource = bindinglist<myObjects>;
datagridview.DataSource = bindingsource;



这是为了正确,或者是否真的重要?我有没有省略任何事情应该在那里?

Is this order correct, or does it really matter? Have I omitted anything which should be there?

任何指针感激,谢谢。

推荐答案

将null分配到DataGridView数据源是要明确,你是正确的网格数据源的最佳方式。

Assigning null to the datagridview DataSource is the best way to clear data source of grid, you are correct.

这篇关于正确的方法,从一个DataGridView取消绑定的BindingSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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