WinForms 控件 > 通用概念 > 概念 > 数据绑定 > 绑定控件到在运行时被创建的数据(2011.10.18更新)
2011-10-18 00:57
393 查看
绑定控件到在运行时被创建的数据 |
Concepts > Concepts > Data
Binding > Binding Controls to Data Created at Runtime
Developer Express data-aware .NET WinForms controls can be bound to databases, XML files and lists of data created at runtime. This topic shows you how to bind controls to lists of data.
绑定控件到在运行时被创建的数据
Suppose you have 一个对象 that represents 一个数据记录 and a list of these records should be displayed in a data-aware control. To allow this list to be bound to a control, the IList, IListSource, ITypedList or IBindingList interface
should be implemented. To supply this list as a data source for a control, use the control's DataSource property.
你可以按照下面的步骤以创建一个记录的列表并且绑定它到一个控件。
声明一个类(Class1)它的实例将表现记录。这个类的公开属性将被作为字段对待。
声明一个类(Class2)它实现IList,IListSource,ITypedList或IBindingList接口。它将表现一个记录的列表(Class1类的对象)并且将表现为一个控件的数据源。
提示:IList,ITypedList和IBindingList接口之间的差异在下面被描述。如果你不想去创建属于你的列表对象,你可以使用任何实现这些接口的已存在的类。对于实例一个System.Collections.ArrayList或System.Array对象can serve
作为一个控件的数据源。这样的话,这个步骤是可选的。
创建一个Class2类的新实例并且用记录填充它。指派这个列表到控件的DataSource属性。
As stated above, the control's 数据源必须实现这些接口中的一个。下面的列表描述了数据源实现每个接口类型之间的差异。
对象实现IList接口。这样的数据源必须有至少1条"记录"。否则,被绑定的控件将不能够去创建任何行。控件被绑定到这样的数据源任何数据变更将不被通知并且这样必须手动更新。
对象实现ITypedList接口。在这个情况下,它不需要为了行被创建而有任何"记录"。数据变更通知不被支持。
对象实现IBindingList接口(从IList派生)。这个数据源类型没有其它接口的缺陷。这个接口声明ListChanged事件,这被用来使控件自更新当被绑定的数据被变更。
See Also
How to: Bind a Control to Data Created at Runtime
Copyright (c) 1998-2011 Developer Express Inc. All rights reserved.
Send Feedback on this topic to DevExpress.
相关文章推荐
- KeyValuePair<byte, string> 类型的数据如何绑定到ComboBox控件上
- Control Study -> 主表和子表数据同时在绑定控件显示(示例代码下载)
- Control Study -> 主表和子表数据同时在绑定控件显示(示例代码下载)
- Control Study -> 主表和子表数据同时在绑定控件显示(示例代码下载)
- WPF Grid 数据绑定,当数据源发生变化后控件值随之更新
- Spring3.X <form:form>标签数据绑定常见异常解决方法
- WPF4数据绑定应用之"创建具有多种显示效果的字串"
- 【212】HDF更新数据&HDF创建
- DataGridView 绑定List<>数据的更新
- AspNetAjaxPager,Asp.Net通用无刷新Ajax分页控件,支持多样式多数据绑定
- Control Study -> Asp.net几个较复杂的显示数据控件(Repeater/DataList/DataGrid)用法 (示例代码下载)
- Flex使用<mx:Tree>控件创建树(可添加和删除节点)
- wpf 绑定数据无法更新ui控件可能存在的问题
- WPF&Silverlight之XamlReader动态创建控件并绑定
- <WP7>(五)手把手教你写天气预报程序:ApplicationBar的使用和ListPicker的数据绑定
- chart&nbsp;控件的各种数据绑定(…
- 【UWP通用应用开发】集合控件与数据绑定
- WPF4数据绑定应用之"创建具有多种显示效果的字串"
- Control Study -> Asp.net几个较复杂的显示数据控件(Repeater/DataList/DataGrid)用法 (示例代码下载)
- 利用UpdatePanel无刷新 更新数据绑定控件