数据绑定在C#和.NET [英] Databinding in C# and .NET

查看:297
本文介绍了数据绑定在C#和.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的新C#和.NET,我strugling一点与数据绑定的整个概念。我所要求的是概念的快速纲要,甚至更好,指向我对网上(preferred)或打印,可以帮助我让我的头周围的想法的来源。

I am pretty new to C# and .NET and I'm strugling a little with the whole concept of databinding. What I am asking for is a quick rundown of the concept, or even better, point me towards sources on the net (preferred) or in print that can help me get my head around the idea.

编辑:

我做我在VS2008的发展,我们正在使用的WinForms

I do my development in vs2008 and we are using winforms

推荐答案

好了,你使用的是什么架构?的WinForms? asp.net? WPF?

Well, what architecture are you using? winforms? asp.net? wpf?

高级的是,如果你有对象,如:

The high level is that if you have objects such as:

public class Person {
    public string Name {get;set;}
    public DateTime DateOfBirth {get;set;}
}

然后你就可以得到约束力的框架来完成所有的辛勤工作,你刚才说你想要绑定 - 例如(的WinForms):

Then you can get the binding framework to do all the hard work, and you just say what you want bound - for example (winforms):

txtName.DataBindings.Add("Text", person, "Name");

这将根据人的姓名文本框的Text属性,并且可以更新人的名称,当用户改变文本。

This sets the textbox's Text property based on the person's Name, and can update the person's Name when the user changes the text.

多记录结合是比较复杂的,并且是基于的IList 中的WinForms / WPF和 IEunmerable 的ASP.NET;这可以让你多个记录绑定(例如为一个网格)。如果列表中提供了额外的功能(排序,通过 IBindingList的 IBindingListView 过滤等等,等等),那么更多的功能。比如是可用的。

Multi-record binding is more complex, and is based on IList in winforms/wpf, and IEunmerable in ASP.NET; this allows you to bind multiple records (for example into a grid). If the list offers extra features (sorting, filtering etc, via IBindingList, IBindingListView, etc), then more functionality might be available.

绑定也允许观察员的用法 - 即变更通知:如果你间接地改变人的名称,那么文本框就会自动更新。这依赖于事件 - 无论是形式公共事件的EventHandler NameChanged;通过,或(更常见了)的 INotifyPropertyChanged的事件(允许一个事件,以通知的多个属性)。

Binding also allows "observer" usage - i.e. change notification: if you indirectly change the person's Name, then the textbox gets automatically updated. This relies on events - either of the form public event EventHandler NameChanged;, or (more commonly now) via the INotifyPropertyChanged event (allowing one event to notify for multiple properties).

某些列表(如的BindingList< T> 数据视图)。也有类似的通知循环

Some lists (such as BindingList<T>, DataView) have similar notification loops.

这篇关于数据绑定在C#和.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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