This is a migrated thread and some comments may be shown as answers.

Exporting grid layout

7 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 08 Mar 2011, 01:50 PM
Hi there.

The users of a page with a grid can make some changes, such as dragging columns around into different orders and things like that.

I'd like to save this layout so that if and when the visitor returns, the grid will be laid out in the same way.

How can I do this?

7 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 08 Mar 2011, 02:02 PM
Hello John,

You can add an order property to your business object of type ID.
Then when reordering the rows, you my update this property.
Later you may achieve persistence , just by sorting on this property  after loading RadGridView again .

An alternative ( less deterministic) would be to count on the fact RadGridView will display items in the order they are present in the source collection.
This means that when you reorder items, you can reorder them in the source collection as well . Later most probably they will appear in this order when rebinding/reloading RadGridView.

All the best,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Steve
Top achievements
Rank 1
answered on 08 Mar 2011, 03:21 PM
I'm not sure if perhaps there is some confusion here... either way I'm not entirely sure what you're getting at. Let me give the problem in greater detail - maybe that will help.

Okay, so we have a grid which has read in some data from somewhere (doesn't matter where), and in that grid we have five columns. Let's say they are UserID, UserName, UserAccess, UserImage and UserPassword. When we first open up the Silverlight application, the user will view the columns in this order.

So let's say the user drags the UserID column so it's between UserName and UserAccess (which they can do with the Telerik grid). Now if this user leaves and comes back, I want them to see that same order (I could store this data in the isolated storage area). If a different user now visits for the first time, they will see the regular order.

I hope that is more clear.
0
Pavel Pavlov
Telerik team
answered on 08 Mar 2011, 03:36 PM
Hi John,

I am sorry for the confusion - my mistake, I was thinking about row reordering.

Now on persisting column order:

1. You can track how the user reorders columns by handling the ColumnReordered event. Each time the user reorders a column , inside the event handler you may save the new order.

2. Later when you load RadGridView, you may read the stored data and set the DisplayIndex property of each column , so that they appear in the same order.

Best wishes,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Steve
Top achievements
Rank 1
answered on 08 Mar 2011, 04:02 PM
Hey Pavel,

That's looking much more like it. I just have a couple of details I'd like to clear up about the solution if I may.

On the event of ColumnReordered I have access to my grid instance which itself contains a collection of columns. The part I'm not sure about is what type they exist as. Let me show you what I mean in code:

for(int i=0; i<radGridView.Columns.Count; i++)
{
     ( radGridView.Columns.ElementAt(i) as ??? )
}

I did look in Telerik.Windows.Controls.GridView and didn't find anything suitable. Well, there is Telerik.Windows.Controls.GridView.Columns, but that's another collection.
0
Accepted
Pavel Pavlov
Telerik team
answered on 08 Mar 2011, 04:23 PM
Hello John,

The base type for all columns is GridViewColumn.
so it should be 
( radGridView.Columns.ElementAt(i) as GridViewColumn )

Kind regards,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Steve
Top achievements
Rank 1
answered on 08 Mar 2011, 04:48 PM
Thankyou very much. You have been very helpful.
0
Gili
Top achievements
Rank 1
answered on 09 Apr 2013, 07:28 AM
i'm trying to use the solution with no luck can you explain more widely pls.
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Steve
Top achievements
Rank 1
Gili
Top achievements
Rank 1
Share this question
or