Hi guys
I agree with Casey's position in Q138613: There must be a clean, official and platform-independent way to access a parent DetailView from a nested ListView. - And I disagree with your position that such access would be improper:
Pure XPO allows (and even requires) access to parent objects in a collection scenario (e.g. one-to-many relationship with XPCollection). Why would you break this principle in XAF on the UI level? Why would it be any less proper to access the parent view than to access the parent object?
I currently have a scenario where I absolutely need this possibility: I have nested ListViews showing the class "Activity" which is linked to several other classes by many-to-many relationships. Now, when ever I create a new Activity within such a nested ListView, I need to find out the "context" (IOW the parent DetailView), so that I can set some default property values on the newly created object. Maybe I want to set the currently active Contact object… or the currently active Project object… etc.
Proposed Solution:
Your abstract base class "View" should contain two new properties:
public abstract View ParentView{ get; }
public abstract IEnumerable<View> ChildViews { get; }
Since your View class is already platform independent, I don't see any additional problems with this concept.
We have closed this ticket because another page addresses its subject:
Platform Independent way to determine Parent DetailView
Hello Daniel,
Thank you for the feedback. Could you please review my last post in the Q138613 issue? It contains information showing how to accomplish your task. Does this meet your needs?
Thanks,
Dennis
Hi Dennis
Thanks for your reply. Your post Q138613 will help me solve the problem.
Is there a specific reason why you only store the DetailView's Id instead of a reference to the DetailView instance?
Hello Daniel,
Thank you for your reply. There is no specific reason, there was just a customer requirement to have the detail view's ID, and I have created my example accordingly. There is no problem if you store the instance of the master detail view.
Thanks,
Dennis
Hi Dennis
Thanks again for your reply!
I have used your source to create another way of accessing the parent DetailView. The advantage of my solution is that the nested ListViews don't have to implement any interfaces… no code is ever necessary in the ListView's ViewController. I have only tested it very briefly, so I can't guarantee that it's bug-free… but it works like a charm for what I need. The main idea is to use extension methods:
-----
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Editors;
namespace Whatever.Module
{
public class GetParentDetailViewController : ViewController
{
public GetParentDetailViewController()
{
TargetViewType = ViewType.DetailView;
TargetViewNesting = Nesting.Root;
}
protected override void OnActivated()
{
base.OnActivated();
ParentViewExtender.AddDetailView(this.View as DetailView);
View.Closing += new EventHandler(View_Closing);
}
void View_Closing(object sender, EventArgs e)
{
ParentViewExtender.RemoveDetailView(sender as DetailView);
}
}
public static class ParentViewExtender
{
private static Dictionary<View, DetailView> viewDictionary;
static ParentViewExtender()
{
viewDictionary = new Dictionary<View, DetailView>();
}
public static DetailView GetParentDetailView(this View view)
{
DetailView res;
if (viewDictionary.TryGetValue(view, out res))
{
return res;
}
else
{
return null;
}
}
public static void AddDetailView(DetailView view)
{
foreach (ListPropertyEditor lpe in view.GetItems<ListPropertyEditor>())
{
viewDictionary.Add(lpe.Frame.View, view);
}
}
public static void RemoveDetailView(DetailView view)
{
foreach (ListPropertyEditor lpe in view.GetItems<ListPropertyEditor>())
{
viewDictionary.Remove(lpe.Frame.View);
}
}
}
}
forgot to mention: In a nested ListView all you have to is call something like:
DetailView parent = GetParentDetailView();
Hello Daniel,
Thank you for the feedback. We already know how to implement this task but we also need to accept the decision on its importance and necessity. Usually our customers provide us with scenarios where they want to have information, not about the master detail view itself, but about its object.
The scenario you described above is not an exception. I have already shown how to accomplish this using existing XAF functionality. So, before introducing some new functionality, we would like to know more about the scenarios, in which the problem can be solve with the new feature better than with existing functionality of XAF. For now, we have no reason to add this new functionality. If our customers provide us with such scenarios, we will revisit this suggestion.
Thanks,
Dennis
Hi Dennis
You're right. In the majority of cases it's sufficient to have access to the master object. I guess I wasn't aware of the correct way to get that information before. I now solved my problem using your official way stated at How to: Access the Master Object from the Nested List View
Thanks for your excellent support and your great products!
Hello Daniel,
Thank you for the feedback. I am glad to know that you can manage your task successfully now. Regarding the suggestion on the ParentView property, we have no objections to implementing it, we just need a reason.
So, I want to say generally to everyone interested in this ticket: just describe a helpful use case requiring accessing the whole master view, and we will be glad to review it, and probably implement the suggested feature.
Thanks,
Dennis