Back to Devexpress

XtraReportBase.GetCurrentRow() Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareportbase-31feb2f8.md

latest6.1 KB
Original Source

XtraReportBase.GetCurrentRow() Method

Returns the current data row from a collection assigned to a report’s Data Member property. If the property is not specified, the method returns the current value from a root collection of the report’s Data Source.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public object GetCurrentRow()
vb
Public Function GetCurrentRow As Object

Returns

TypeDescription
Object

The current data row.

|

Remarks

Use the GetCurrentRow method when you bind a report to a business object (such as Object Data Source, EF Data Source, or XPO Data Source) to retrieve data from the object’s methods or properties with custom logic. Call the GetCurrentRow method in control event handlers (for example, in a BeforePrint handler) to obtain a business object, then get a value from the object’s method or property.

csharp
private void xrLabel1_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    var currRow = GetCurrentRow();
}
vb
Private Sub xrLabel1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles xrLabel1.BeforePrint
    Dim currRow = GetCurrentRow()
End Sub

If you want to get the current value of a data source column (field), use the GetCurrentColumnValue(String) method instead.

Get the Current Row in a Detail Report

To get the current data row from a collection assigned to a detail report’s Data Member (Data Source) property, call the detail report’s GetCurrentRow method in control event handlers (for example, in a BeforePrint handler).

csharp
private DevExpress.XtraReports.UI.DetailReportBand DetailReport1;

private void xrLabel2_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    var currRow = DetailReport1.GetCurrentRow();
}
vb
Private DetailReport1 As DevExpress.XtraReports.UI.DetailReportBand

Private Sub xrLabel2_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles xrLabel2.BeforePrint
    Dim currRow = DetailReport1.GetCurrentRow()
End Sub

You can also use a control’s Report property to access the report to which the control belongs. This property can be useful if your report consists of multiple nested detail reports, and you want to access a control’s detail report in a control event handler.

csharp
using DevExpress.XtraReports.UI;
// ...
private void xrLabel3_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    var label = sender as XRLabel;
    var currRow = label.Report.GetCurrentRow();
}
vb
Imports DevExpress.XtraReports.UI
' ...
Private Sub xrLabel3_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles xrLabel3.BeforePrint
    Dim label = TryCast(sender, XRLabel)
    Dim currRow = label.Report.GetCurrentRow()
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetCurrentRow() 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.

reporting-winforms-create-hierarchical-report-from-flat-table/CS/TreeViewReport/ChildReport.cs#L16

csharp
XRSubreport subReport = sender as XRSubreport;
ParentNode parentNode = this.GetCurrentRow() as ParentNode;
ChildReport childReport = new ChildReport();

See Also

GetPreviousRow()

GetNextRow()

XtraReportBase Class

XtraReportBase Members

DevExpress.XtraReports.UI Namespace