in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Access to a User object from the User-Roles ListView

Last post 11/12/2007 10:39 AM by Dennis (Developer Express). 3 replies.
Page 1 of 1 (4 items)
Sort Posts:
Previous Next
  • 11/11/2007 10:12 PM

    Access to a User object from the User-Roles ListView

    There is a ViewController with an Action created in the MainDemo. The TargetViewId of this controller is the User-Roles ListView. How can i get access to the User object from the Execute event handler of the Action?

  • 11/12/2007 8:08 AM In reply to

    Re: Access to a User object from the User-Roles ListView

    Hi Alexander,

    You can use the following code to access the root detail view current object:

    public partial class ViewController1 : ViewController { 
          
    static private DetailView _rootDetailView = null;
           
    public ViewController1() {
                InitializeComponent();
                RegisterActions(components);
                simpleAction1.TargetViewId =
    "User_Roles_ListView";
            }
           
    private void ViewController1_Activated(object sender, EventArgs e) {
               
    if (View is DetailView && View.IsRoot && typeof(User).IsAssignableFrom(View.ObjectType)) {
                    _rootDetailView = (
    DetailView)View;
                }
            }
           
    private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
               
    User user = (User)_rootDetailView.CurrentObject;
                System.Windows.Forms.
    MessageBox.Show(user.FullName);
            }
           
    private void ViewController1_Deactivating(object sender, EventArgs e) {
               
    if (View is DetailView && View.IsRoot && typeof(User).IsAssignableFrom(View.ObjectType)) {
                    _rootDetailView =
    null;
                }
            }
        }

    Thanks,
    Dennis

    Developer Express Support
  • 11/12/2007 9:34 AM In reply to

    Re: Access to a User object from the User-Roles ListView

    private void ViewController1_Activated(object sender, EventArgs e) {
               
    if (View is DetailView && View.IsRoot && typeof(User
    ).IsAssignableFrom(View.ObjectType)) {
                    _rootDetailView = (
    DetailView
    )View;
                }
            }


    Can not use it.

    The _rootDetailView will be NULL,

    because the View is User_Roles_ListView. It is not a DetailView and View.IsRoot==false ...

  • 11/12/2007 10:39 AM In reply to

    Re: Access to a User object from the User-Roles ListView

    Alexander,

    I forgot to say that you don't specify the TargetViewId property of your view controller to force it work, sorry (null value is caused by the fact that the root detail view activates by last).
    Instead you can check the required view manually as shown in my example from the previous post.

    P.S. 
    See also the "Access root DetailView ObjectType from nested DetailView" issue at
    http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=Q50590 where discussed another solution for similar task. It approaches when you have 1-M relationship and you want to access the root object from the child view.

    But if you really wish to access the root detail view current object from the controller with
    TargetViewId = "User_Roles_ListView";
    then you can use the following code:

    namespace Solution1.Module.Win {
        public partial class ViewController2 : ViewController {
            static User user = null;
            public ViewController2() {
                InitializeComponent();
                RegisterActions(components);
                TargetViewId = "User_Roles_ListView";
            }
            private void ViewController2_Activated(object sender, EventArgs e) {
                Application.DetailViewCreated += new EventHandler<DetailViewCreatedEventArgs>(Application_DetailViewCreated);
            }
            void Application_DetailViewCreated(object sender, DetailViewCreatedEventArgs e) {
                
    if (Application != null) {
                   
    if (e.View.Id == Application.FindDetailViewId(typeof(User))){
                        user = (
    User)e.View.CurrentObject;
                    }
                }
            }

            private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
                System.Windows.Forms.MessageBox.Show(user.FullName);
            }
        }
    }

    I have included a sample, which illustrates both options in the attachment.
    Thanks,
    Dennis

    Developer Express Support
Page 1 of 1 (4 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED