Hello,
I've made a custom LookupControlTemplate in which I can use advanced filtering for the listview. Now, I only want to use this template when looking up a specific domain object, in this case the Article item. Currently, I'm using the application.CreateCustomTemplate event to show the new template, but I can't seem to use it for the Article object only. Can anyone help me?
Thanks in advance
Xavier
Use LookupControlTemplate for specific domain object
Answers
Hello Xavier,
Thanks for your patience. I have attached a modified version of your sample showing how to solve your problem. Please let me know in case of any difficulty.
Let me also elaborate on the ideas behind this solution:
- Create a new show view strategy class, derived from the existing strategy (for instance from the ShowInMultipleWindowsStrategy) and with a System.Type property (DetailViewObjectType):
C#public class MyShowInMultipleWindowsStrategy : ShowInMultipleWindowsStrategy {
public MyShowInMultipleWindowsStrategy(XafApplication application) : base(application) { }
private Type \_detailViewObjectType;
public Type DetailViewObjectType { get { return \_detailViewObjectType; }
}
protected override void ShowViewCore(ShowViewParameters parameters, ShowViewSource showViewSource) {
\_detailViewObjectType = null;
if (parameters.CreatedView is DetailView)
{
if (parameters.CreatedView.ObjectType == typeof(DomainObject1)
|| parameters.CreatedView.ObjectType == typeof(DomainObject2)
|| parameters.CreatedView.ObjectType == typeof(DomainObject3)) {
\_detailViewObjectType = parameters.CreatedView.ObjectType;
}
}
base.ShowViewCore(parameters, showViewSource);
}
}
- Override the ShowViewCore method to obtain the information about the currently opened view to determine its object type.
It will be accessed via the DetailViewObjectType property. - Declare a custom application class, derived from the WinApplication class, and override the CreateShowViewStrategy virtual method to create the required strategy:
C#public class MyWinApplication : WinApplication {
protected override ShowViewStrategyBase CreateShowViewStrategy() {
return new MyShowInMultipleWindowsStrategy(this);
}
}
- Create a custom template for the required object type as described in Template Customization.
C#static void Main() {
//...
MyWinApplication winApplication = new MyWinApplication();
winApplication.CreateCustomTemplate += new EventHandler<CreateCustomTemplateEventArgs\>(winApplication\_CreateCustomTemplate);
//...
}
static void winApplication\_CreateCustomTemplate(object sender, CreateCustomTemplateEventArgs e) {
if (e.Context.Name == TemplateContext.View) {
Type objectType = ((MyShowInMultipleWindowsStrategy)(((MyWinApplication)sender).ShowViewStrategy)).DetailViewObjectType;
if (objectType == null) {
e.Template = new DevExpress.ExpressApp.Win.CustomTemplates.DetailViewForm();
return;|
}
if (objectType == typeof(DomainObject1))
e.Template = new DevExpress.ExpressApp.Win.CustomTemplates.DetailViewForm1();
else
if (objectType == typeof(DomainObject2))
e.Template = new DevExpress.ExpressApp.Win.CustomTemplates.DetailViewForm2();
else
if (objectType == typeof(DomainObject3))
e.Template = new DevExpress.ExpressApp.Win.CustomTemplates.DetailViewForm3();
}
}
}
Thanks,
Dennis
Hello Xavier,
Sure, we can help you.
Please refer to the Associating Classes with DetailViews thread on our forum, where a solution to your task is discussed.
Let me know if it helps you.
Thanks,
Dennis
Hello Dennis,
Thanks for the fast reply and the information. I tried the solution and got it to work, but it isn't really what I'm looking for. What I want to do is, for instance, I have an PriceInquiry object in which I have an Article object and a Unit object. In the PriceInquiry_DetailView, while selecting the Article, I want to use my custom LookupControlTemplate to look it up. The Unit object, however, should be looked up by the standard LookupControl. Any ideas on how to achieve this?
Thanks in advance,
Xavier
Hello Xavier,
>>
What I want to do is, for instance, I have an PriceInquiry object in which I have an Article object and a Unit object. In the PriceInquiry_DetailView, while selecting the Article, I want to use my custom LookupControlTemplate to look it up. The Unit object, however, should be looked up by the standard LookupControl. Any ideas on how to achieve this?
<<
I understand your task, and the solution I gave you previously is exactly what you need. The idea of this solution is to "remember" the type of a shown view (if it is a ListView) in the ShowViewCore method of a custom strategy. Then, you should access this object type in the CreateCustomTemplate event handler and apply a custom template only if the context is the LookupControlTemplate, and the object type is the required object type. I assume that you used the solution from the forum post "as is", and that's why you thought that it wouldn't meet your requirements.
So, now you should slightly modify it according to your own scenario. Please send me your sample in case of any difficulty. I will be glad to review it.
Thanks,
Dennis
Hello Dennis,
I took a closer look at it, and got it to work! Thanks alot for the help.
Thanks,
Xavier
Solved.
Hello Dennis,
Sorry for bothering u with this problem again. I thought I had it figured out, but apparently, it didn't work out at all. I've been trying to find out how to do it, but with no result. Would u mind taking a closer look at it please? I've included a testproject and a screenshot of what I want to achieve.
Thanks in advance
Xavier
Hello Xavier,
Thanks for the sample. We are working on it and will answer ASAP.
Thanks,
Dennis