The requested page is not available for the requested platform. You are viewing the content for Default platform.

XRControl.DataBindings Property

Provides access to the collection of a control's bindings.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.1.dll

Declaration

[SRCategory(ReportStringId.CatData)]
public virtual XRBindingCollection DataBindings { get; }
<SRCategory(ReportStringId.CatData)>
Public Overridable ReadOnly Property DataBindings As XRBindingCollection

Property Value

Type Description
XRBindingCollection

An XRBindingCollection value, specifying the collection of the control's bindings.

Remarks

Note

This property is in effect when a UserDesignerOptions.DataBindingMode is set to DataBindingMode.Bindings.

To bind a control's property to the property of a data source, add an XRBinding object to the control's collection.

At design time, a control's data binding is allowed to be incorrect, assuming that a data source may be provided at runtime. However, if the data binding still remains incorrect at the time a report document is being generated, the data binding is assumed to be not set, and a control is treated as unbound.

To learn more on using the DataBindings property, refer to Binding Report Controls to Data.

Not all descendants of the XRControl class use the DataBindings property. For example, the Band class descendants ignore the DataBindings property.

Examples

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 demo Northwind database (nwind.mdb file located in the directory, where you installed DevExpress demos).

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);
    }

}
See Also