我应该使用什么:List或BindingList? [英] What should i use : List or BindingList ?

查看:174
本文介绍了我应该使用什么:List或BindingList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我正在使用VB.net 2017和实体框架6.

I'm using VB.net 2017 and entity Framework 6.

我有这种情况:

- 在我的数据库中我有2个表:学生和学生成绩(作为孩子)

- in my database I have 2 tables : Students and StudentResults ( as a child )

- 我有2个bindingsource:Studentbindingsource(绑定到学生)和ResultsBindingsource(绑定到StudentResults)

- I have 2 bindingsource : Studentbindingsource (bound to students ) and ResultsBindingsource ( bound to StudentResults )

- 我有2个datagridview分别绑定到这些绑定源。

- I have 2 datagridview bound respectively to these bindingsources.

现在我的问题是:当我为2 bindingsource设置数据源时,我应该使用.Tolist还是.Tobindinglist?

Now my question is : when I set the datasource for the 2 bindingsource , should I use the .Tolist or .Tobindinglist ?

例如:Studentbindingsource.datasource = context.Students.Local.Tolist或
context.Students.Local.ToBindingList?

for example : Studentbindingsource.datasource=context.Students.Local.Tolist or context.Students.Local.ToBindingList ?

谢谢!   ;

Thank you ! 

推荐答案

BindingList有一个Changed事件

https://docs.microsoft.com/en-us/dotnet/api/system。 componentmodel.bindingl ist-1.listchanged?view = netframework-4.7.2

https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.bindinglist-1.listchanged?view=netframework-4.7.2

当列表或项目出现时列表更改。

如果列表更改或列表中的项目更改为使用DB执行某种CRUD操作,那将是一件好事。

It would be good if the list changes or and item in the list changes to do some kind of CRUD operation with the DB.

List没有这样的事件,你必须在列表中查询对象状态,例如 添加,修改和删除,如果对象在链接中有一些状态感知,如信息。

The List doesn't have such an event, and you would have to query an object in the list for object state, like  add, modified and delete, if the object had some state awareness like information in the link.

http://www.dailycoding.com/Posts/maintaining_dirty_and_new_state_of_objects.aspx

http://www.dailycoding.com/Posts/maintaining_dirty_and_new_state_of_objects.aspx





这篇关于我应该使用什么:List或BindingList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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