Back to Devexpress

XtraReportBase.GetCurrentColumnValue(String) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareportbase-dot-getcurrentcolumnvalue-x28-system-dot-string-x29.md

latest8.3 KB
Original Source

XtraReportBase.GetCurrentColumnValue(String) Method

Returns the current value of the specified column (field) 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 GetCurrentColumnValue(
    string columnName
)
vb
Public Function GetCurrentColumnValue(
    columnName As String
) As Object

Parameters

NameTypeDescription
columnNameString

A column (field) name.

|

Returns

TypeDescription
Object

The current column (field) value. If the specified column (field) was not found, the method returns null.

|

Remarks

Call the GetCurrentColumnValue method in control event handlers (for example, in a BeforePrint handler).

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

Business objects (such as Object Data Source, EF Data Source, or XPO Data Source) might contain methods or properties with custom logic. To get the current value from such methods or properties, use the GetCurrentRow method. Call this method to obtain a business object, then get a value from the object’s method or property.

Get the Current Column (Field) Value in a Detail Report

To get the current column (field) value from a collection assigned to a detail report’s Data Member (Data Source) property, call the detail report’s GetCurrentColumnValue 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 currValue = DetailReport1.GetCurrentColumnValue("ProductName");
}
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 currValue = DetailReport1.GetCurrentColumnValue("ProductName")
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 currValue = label.Report.GetCurrentColumnValue("ProductName");
}
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 currValue = label.Report.GetCurrentColumnValue("ProductName")
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetCurrentColumnValue(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.

asp-net-mvc-grid-create-report-based-on-grid-layout/CS/E4755/Controllers/HomeController.cs#L58

csharp
void control_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    if (Convert.ToBoolean(((XRShape) sender).Report.GetCurrentColumnValue("Discontinued")) == true)
        ((XRShape) sender).FillColor = Color.Yellow;

asp-net-web-forms-grid-create-report-based-on-grid-layout/CS/WebApplication1/Default.aspx.cs#L41

csharp
void control_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    if(Convert.ToBoolean(((XRShape)sender).Report.GetCurrentColumnValue("Discontinued")) == true)
        ((XRShape)sender).FillColor = Color.Yellow;

asp-net-mvc-grid-create-report-based-on-grid-layout/VB/E4755/Controllers/HomeController.vb#L57

vb
Private Sub control_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    If Convert.ToBoolean((CType(sender, XRShape)).Report.GetCurrentColumnValue("Discontinued")) = True Then
        CType(sender, XRShape).FillColor = Color.Yellow

asp-net-web-forms-grid-create-report-based-on-grid-layout/VB/WebApplication1/Default.aspx.vb#L46

vb
Private Sub control_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    If Convert.ToBoolean(DirectCast(sender, XRShape).Report.GetCurrentColumnValue("Discontinued")) = True Then
        DirectCast(sender, XRShape).FillColor = Color.Yellow

See Also

GetCurrentColumnValue<T>(String)

XtraReportBase Class

XtraReportBase Members

DevExpress.XtraReports.UI Namespace