创建绑定源的副本 [英] Creating a Copy of bindingsource

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

问题描述

我正在使用VS2008,这是Window Forms C#应用程序

任何人都可以帮助我创建一个已创建的绑定源的副本,并将其分配给新创建的DGV,因为我在运行时以及每次需要新数据的应用程序中使用了多个DGV,因此我想过滤现有数据源并创建一个副本并将其分配给DGV.

请帮帮我.

谢谢.

I am using VS2008, a Window Forms C# application

Any one help me to create a copy of already created binding-source and assign it to newly created DGV because I am using several DGV in my application created in run time and every time it needs new data so I want to filter the existing data source and create a copy of it and assign it to DGV.

Please help me.

Thanks.

推荐答案

完成副本后,您是否希望两个副本都作为一个源或彼此独立工作?如果希望它们独立运行,请使用以下代码创建现有DataSource的副本,然后对其进行过滤并应用于其他DGV.


Once you have done the copy, do you want both the copies to work as one source or independent of each other? If you want them to behave independent, create a copy of the existing DataSource using following code and then filter it and apply to the other DGVs.


MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memorySteram, dataSourceObject);
newDataSource = formatter.Deserialize(memoryStream);


除非我误解了您的问题,否则无需复制"现有的BindingSource.

像这样的东西:
Unless I have misunderstood your question, there is no need to ''copy'' the existing BindingSource.

Something like:
BindingSource newBindingSource = new BindingSource();
newBindingSource.DataSource = oldBindingSource.DataSource;
newBindingSource.Filter = "FirstName = Smith";  // Or whatever

newDataGridView.DataSource = newBindingSource;


尝试执行此操作以复制BindingSource对象.

Try this to make a copy of a BindingSource object.

BindingSource newBindingSource = new BindingSource(oldBindingSource.DataSource, oldBindingSource.DataMember);


这篇关于创建绑定源的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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