DevExpress XtraGrid DATA BINDING METHODS

本文介绍了网格控件的数据绑定方法,包括使用 .NET 数据提供程序从数据库获取数据、绑定 XML 数据以及运行时创建的数据绑定。针对不同数据源,文章详细解释了 DataSource 和 DataMember 属性的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 Two Important Proptery

   This property is used when the DataSource property refers to a dataset containing several data tables. The DataMember property should specify the desired table's name in this case. The specified table's data is supplied for the grid control's main view.

   If the DataSource property refers to a data table, data view or any custom created data source object, the DataMember property should not be used.


DATA BINDING METHODS

To bind a grid control to a data source, you will need to use its GridControl.DataSource property. Note that this doesn't depend on the data binding method that you choose. Additionally, you may need to use the GridControl.DataMember property. This is necessary if the specified data source is a dataset containing several tables. In this case, the GridControl.DataMember property identifies which of the available tables must be bound to the grid. In other cases, this property value is ignored.

Data binding methods differ in how to obtain an object assigned to the GridControl.DataSource property. This depends on the type of data to which the grid must be bound. You can bind the grid to data from a database, from an XML file or to any data created at runtime. Thus, three data binding methods are available:

  • Using .NET Data Providers

    This method implies that data is stored in a database. You can bind your grid control to such data using one of the two data adapter components supplied: OleDBDataAdapter and SqlDataAdapter. The first accesses data sources exposed using OLE DB. The second is designed to work with data sources provided by Microsoft SQL Server version 7.0 or later. Both data adapters use connection objects to bind to data and are capable of generating DataSet objects that contain data tables. Data tables (or data views bound to tables) can be bound to the grid by assigning them directly to the GridControl.DataSource property. You can also assign the DataSet object generated to the GridControl.DataSource property and specify the table name using the GridControl.DataMember property.

  • Binding to XML Data

    This method uses data stored in an XML file. To access such data, you need to create a DataSet object and use its ReadXML method. This results in the creation of appropriate tables within the DataSet. Once tables are created, they can be bound to the grid control. Again, this can be done by a direct assignment to the GridControl.DataSource property or by using the GridControl.DataSource and GridControl.DataMember properties in combination.

  • Binding to Data Created at Runtime

    The data object created is assigned to the GridControl.DataSource property. This object must support the IList, ITypedList or IBindingList interface.

    Note that you don't have to create custom data source objects. You can use a DataTable object filled with data at runtime, if it suits your needs.

    The image below illustrates all the data binding methods mentioned:.111

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值