XRBindingCollection.Add(String, Object, String) Method
Creates an XRBinding object and adds it to the collection.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v24.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
propertyName | String | The name of the control’s property to bind. |
dataSource | Object | An object that represents the data source. |
dataMember | String | A string containing a navigation path resolving to the property of an object. |
Returns
Type | Description |
---|---|
XRBinding | An XRBinding object. |
Example
The following two methods demonstrate how to add and remove an XRBinding object from the control’s collection of data bindings. Data bindings are added in two different ways. For the lbUnitPrice label the binding is first created and then added, for the lbProductName label the binding is created and added simultaneously.
Note that for this example to work correctly, a report must contain the dsProducts dataset, which should use data in the Products table (“SELECT Products.* FROM Products”) from the sample Northwind database.
using DevExpress.XtraReports.UI;
// ...
public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
// ...
public void AddBindings() {
// Create a data binding.
XRBinding binding = new XRBinding("Text", dsProducts1, "Products.UnitPrice");
// Add the created binding to the binding collection of the lbUnitPrice label.
lbUnitPrice.DataBindings.Add(binding);
// Create and add the binding to the binding collection of the lbProductName label.
lbProductName.DataBindings.Add("Text", dsProducts1, "Products.ProductName");
}
public void RemoveBinding(XRControl control, string propertyName) {
// Get the data binding specified by the control's property name.
XRBinding binding = control.DataBindings[propertyName];
// Remove the data binding from the control's binding collection.
if(binding != null)
control.DataBindings.Remove(binding);
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(String, Object, String) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.