Back to Devexpress

View.CurrentObject Property

expressappframework-devexpress-dot-expressapp-dot-view-9b3b855e.md

latest6.7 KB
Original Source

View.CurrentObject Property

Specifies a View‘s current object.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public virtual object CurrentObject { get; set; }
vb
Public Overridable Property CurrentObject As Object

Property Value

TypeDescription
Object

An object representing the current View’s current object.

|

Remarks

The example below demonstrates how to set a Contact ‘s FirstName value to the NickName property via a SimpleAction.

csharp
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using MainDemo.Module.BusinessObjects;
// ...
public class SetNickNameController : ViewController {
    public SetNickNameController() {
        SimpleAction setNickNameAction = new SimpleAction(this, "SetNickName", PredefinedCategory.Edit);
        setNickNameAction.Execute += SetNickNameAction_Execute;
    }
    private void SetNickNameAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        Contact currentObject = View.CurrentObject as Contact;
        if(currentObject != null) {
            currentObject.NickName = currentObject.FirstName;
        }
    }
}

This property returns null and is intended to be overridden in View descendants. See ListView.CurrentObject and DetailView.CurrentObject.

For additional information, refer to the How to: Access Objects Selected in the Current View help topic.

The following code snippets (auto-collected from DevExpress Examples) contain references to the CurrentObject property.

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.

xaf-how-to-create-information-panels/CS/InfoPanels.Module.Win/Controllers/InfoPanelViewControllerWin.cs#L40

csharp
label.Text = "The current View is " + View.Caption;
if (View.CurrentObject != null) {
    label.Text += System.Environment.NewLine +

xaf-how-to-highlight-invalid-properties-when-a-view-is-activated/CS/EFCore/ValidateHighlightEF/ValidateHighlightEF.Module/Controllers/ImmediateValidationController.cs#L48

csharp
ImmediateValidationTargetObjectsSelector objectsSelector = new ImmediateValidationTargetObjectsSelector();
    ValidateObjects(objectsSelector.GetObjectsToValidate(View.ObjectSpace, View.CurrentObject));
}

xaf-how-to-save-the-currently-opened-view-as-a-new-view-variant-at-runtime/CS/EF/ViewVariantSaveEF/ViewVariantSaveEF.Module/Controllers/UserViewVariantsController.cs#L129

csharp
string data = Convert.ToString(dialogController.Tag);
ViewVariantParameterObject parameter = dialogController.Window.View.CurrentObject as ViewVariantParameterObject;
if (data == STR_NewViewVariant_Id) {

xaf-how-to-show-persistent-objects-in-a-non-persistent-objects-view/CS/EFCore/ComplexDialogEF/ComplexDialogEF.Module/Controllers/MyController.cs#L27

csharp
void action_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
    OrderTemplate parameters = (OrderTemplate)e.PopupWindow.View.CurrentObject;
    ListPropertyEditor listPropertyEditor = ((DetailView)e.PopupWindow.View).FindItem("Services") as ListPropertyEditor;

xaf-how-to-access-the-master-detailview-information-from-a-nested-listview-controller/CS/EFCore/GetMasterFrameEF/GetMasterFrameEF.Module/Controllers/MyTaskController.cs#L12

csharp
if (masterController != null) {
    masterController.MyAction.Caption = View.CurrentObject != null ? ((MyTask)View.CurrentObject).Subject : "Empty";
}

xaf-how-to-create-information-panels/VB/InfoPanels.Module.Win/Controllers/InfoPanelViewControllerWin.vb#L39

vb
label.Text = "The current View is " & View.Caption
If View.CurrentObject IsNot Nothing Then
    label.Text &= System.Environment.NewLine & "The current object is " & View.CurrentObject.ToString()

See Also

DetailView.SelectedObjects

ListView.SelectedObjects

View Class

View Members

DevExpress.ExpressApp Namespace