Back to Devexpress

XRBindingCollection.Remove(XRBinding) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrbindingcollection-dot-remove-x28-devexpress-dot-xtrareports-dot-ui-dot-xrbinding-x29.md

latest4.3 KB
Original Source

XRBindingCollection.Remove(XRBinding) Method

Removes the specified binding from the collection.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public void Remove(
    XRBinding binding
)
vb
Public Sub Remove(
    binding As XRBinding
)

Parameters

NameTypeDescription
bindingXRBinding

An XRBinding object to remove from the collection.

|

Remarks

The elements that follow the removed XRBinding object in the collection move up to occupy the vacated spot.

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.

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

}
vb
Imports DevExpress.XtraReports.UI
' ...

Public Class XtraReport1
    Inherits DevExpress.XtraReports.UI.XtraReport
' ...

    Public Sub AddBindings()
        ' Create a data binding.
        Dim binding As 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")
    End Sub

    Public Sub RemoveBinding(ByRef control As XRControl, ByRef propertyName As String)
        ' Get the data binding specified by the control's property name.
        Dim binding = control.DataBindings(propertyName)

        ' Remove the data binding from the control's binding collection.
        If (Not (binding Is Nothing)) Then
            control.DataBindings.Remove(binding)
        End If
    End Sub
End Class

See Also

Bind Report Controls to Data Using Expression Bindings

XRBindingCollection Class

XRBindingCollection Members

DevExpress.XtraReports.UI Namespace