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

Gary's Blog

XAF – View Variants

In this post we are going to look at how to provide customized variants of the same List View, and allow an end-user to choose the desired view at runtime. We’ll work with the Contact list view as an example. But first, let’s look at what a view variant is and why you’d want to construct one.

A view variant is simply a variant of a view (the clue’s in the name as we say) and you’d create one if, for example, you had a business object with a large number of properties and you only wished to show a sub set of those properties to a particular user. Okay, so know we know the what’s and the why’s, let’s get on with the how’s shall we?

We’ll use the Module Editor to create two variants of the Contact list view and use a view action to allow the user to switch between them. The first thing we have to do is to add the View Variants module to your MySolution.Module project. For this purpose, find the XXXModule.cs  file in the MySolution.Module project displayed in the Solution Explorer. Double-click this file. The Module Designer will be invoked. In the Toolbox, navigate to the DX: XAF Modules tab and drag the ViewVariantsModule item from this page to the Designer's RequiredModules section, like so:

Now we have to rebuild our solution so that the changes made in the Module Designer are visible to the Application Model. Having done that we can invoke the Model Editor for the MySolution.Module the right-click the Application | Views node and select Add | ListView. For the new node, set the ID attribute to the Contact_ListView_AllColumns value and the ClassName attribute to the MySolution.Module.Contact value. Now, right-click the newly created node and select GenerateContent. Columns will be generated using information on the specified class (BOModel | Contact node) and its ancestors. Leave these columns as they are. This List View will represent the “complete” variant for the Contact List View.

Next, navigate to the Application | Views | Contact_ListView node, expand the Variants node and for the Default child node, set the Caption attribute to Few columns. Next, right-click the Variants node and select Add Variant. For the new node, set the Contact_ListView_AllColumns value for the ViewID attribute, set the All columns value for the ID and Caption attributes. Don’t forget to save the changes. :-)

Okay, let’s test it out now, run the application (WinForms or WebForms you choose). Select the Contacts item in the navigation control. For the displayed Contact List View the View Action will be activated. This Action's items represent the Contact_ListView_CompleteVariant and Contact_ListView_ShortenedVariant nodes that were specified in the Model Editor. If you’ve been following along, and you run the WinForms app, then you should see something like this:

Oliver and I also did a video on this subject, you should check it out if you want more information.

Digg This
Published Dec 03 2008, 03:58 PM by Gary Short (Developer Express)
Filed under:
Technorati tags: XAF

Comments

 

Alain Bismark said:

Hi Gary

The link of video is not working.

Thanks

December 3, 2008 2:48 PM
 

Steven Rasmussen said:

Thanks for the info.  I was wondering how to make the view variants work.  :)

December 3, 2008 3:16 PM
 

Gary Short (Developer Express) said:

Thanks Alain, so kind of weirdness going on, should be working fine now.

December 3, 2008 3:17 PM
 

Vellayan Lakshmanan said:

Hi,

We have recently tried XAF and found some hiccups.  We are in the process of creating Database oriented application through XAF.  We need some support on the following: 1) A sample to explain the Storing and Fetching of dataset in a DB application.2) In Scheduler - We need to post back the task set that are user entered in an application to the Scheduler component instead of moving the dataset intermittently to the native table called EVENT, which of course we are not able to get it done or would be appreciable if you could provide a sample on the same.

Looking forward for your kind reply

December 23, 2008 8:46 AM
 

Gary Short (Developer Express) said:

Hello Vellayan,

The most direct route for support of this nature is via the support centre at:

www.devexpress.com/.../Center

Cheers,

Gary

December 23, 2008 9:04 AM

Leave a Comment

(required)  
(optional)
(required)  
Verification code: Required
   
Add
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED