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

Re-order rows in "endless scrolling" grid...?

8 Answers 108 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kennet
Top achievements
Rank 2
Kennet asked on 24 May 2010, 02:25 PM
OK, to make sense to this question...

First I use this SL example in WPF for re-order rows: http://blogs.telerik.com/blogs/posts/10-05-20/enable_radgridview_rsquo_s_rows_reorder_functionality_using_behaviors.aspx 

That works kind of, exept for this pice of code tht I think is specific for SilverLight, not sure how to convert this:
public static Image ToImage(this FrameworkElement element, Transform transform)  
        {  
 
                var elementAsImage = new Image();  
 
                WriteableBitmap bitmap = new WriteableBitmap(element, transform);  
                elementAsImage.Source = bitmap;  
                elementAsImage.Opacity = 0.85;  
                return elementAsImage;  
         } 

And second I like to use this with Vladimir's code for "Endless scrolling of 2mil. records" that is updated for Q2010 here: http://www.telerik.com/ClientsFiles/159249_wpfapplication1.zip

I need the "Endless scrolling of 2mil. records" code woring with ObservableCollection instead what it use now. How do I do that?

Help...

8 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 27 May 2010, 10:37 AM
Hello Kennet,

I have added the code related to creating image in WPF. The needed is the following:
var elementAsImage = new Image();
 
           RenderTargetBitmap bitmap = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 96, 96, PixelFormats.Pbgra32);
 
           //Workaround for bug in position of the screenshoted image (takes snapshots only from position 0,0).
           VisualBrush sourceBrush = new VisualBrush(element) { Stretch = Stretch.None };
           DrawingVisual drawingVisual = new DrawingVisual();
           DrawingContext drawingContext = drawingVisual.RenderOpen();
 
           using (drawingContext)
           {
               drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(element.ActualWidth, element.ActualHeight)));
           }
 
           bitmap.Render(drawingVisual);
 
           elementAsImage.Source = bitmap;
           elementAsImage.Opacity = 0.85;
           return elementAsImage;

However, combining this functionality with Endless Scrolling is not trivial task. Let me explain this in detail -  Endless scrolling basic idea is to get the data from the server (in this case database) when it is needed. If the data is kept in memory using such mechanism will be useless, since RadGridView supports UI virtualization. To achieve this endless scrolling mechanism uses the following :
      * QueryableCollectionView recieves IQueryable as source collection. Since QueryableCollectionView implements paging it can load only portions of the data. In addition pass information about sorting and grouping directly to the database.
 - Since QueriableCollectionView is only View it does not support operations such as Insert, Remove, etc. To enable such operations it would require this to be supported by the source collection (however, in this case IQueryable).

I have created on possible solution using proxy that provides Reorder functionality and implements the IQueryable. Please, check the attached project as reference.

If you have any other questions or issues do not hesitate to contact us.

Kind regards,
Tsvyatko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kennet
Top achievements
Rank 2
answered on 27 May 2010, 01:55 PM
Hi Tsvyatko,

Thanks for the answer and code.

I kind of work as I like, but for example if I drag row #5 and drop it on row #2 the the rows swicth places, I want the dragged row to insert where I dropp it.

I was thinking, is it possible that the DB results from QueriableCollectionView just adds to a ObservableCollection<MyClass> . Every time the grid need more data IQueryable just add these rows to my ObservableCollection<MyClass>. and I have ObservableCollection<MyClass>.  as ItemsSouce for my RadGrid.

This would be perfect for my project sine I need to update som "rows" with status message, And I can update the DB in background when a item is inserted, update or deleted. 

How can I do that?


/Ken
0
Tsvyatko
Telerik team
answered on 31 May 2010, 11:56 AM
Hi Kennet,

I have extended IReorderable Interface in order to make it insert dragged item before destination one. I have included the modification in the attached project.

About using the ObservableCollection - As I understand you want infrastructure as following - DB -> IQueryable -> QueryableCollectionView -> ObservableCollection -> RadGridView

In order to do this you need the following modifications in the existing project:
- inherit ObservableCollection and create your own that override insert method to add the logic from InsertBefore callback (modify display indexes).

 - use QueryableCollectionView as source for the ObservableCollection

However using this approach, sorting and filtering will not be executed on the SQL server but instead as inline queries only on the subset of the data that is already loaded in the memory.

Best wishes,
Tsvyatko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kennet
Top achievements
Rank 2
answered on 31 May 2010, 01:11 PM
Hi Tsvyatko,

Thanks for you response, we are getting close now...

This is good I think I can use this. But since I'm new to advance Linq, how do I use QueryableCollectionView as source for my ObservableCollection?

Also what is the best way to update the data already loaded in the grid? (If I change the data outside my application) I have tested "dataControl.Rebind();"  that works, but can take some time to execute.

Best
Kennet
0
Tsvyatko
Telerik team
answered on 31 May 2010, 01:50 PM
Hi Kennet,

In order to use QueryableCollectionView as source to Observable Collection, the following is needed:

 - fill to ObservableCollection with all the items that appears there
 - Subscribe to CollectionChanged of the QueryableCollectionView and perform the operation indicated in Action property of the argument (update ObservableCollection).

 - Subscribe to your Observable collection; CollectionChanged event and update QueriableCollectionView.

 - use some kind of flagging in order to avoid loops in the synchronization process.

About the GridView update please check these lines of code from the RowReorder behavior:
if (!this.ItemsSourceSupportNotifications)
  {
   this.AssociatedObject.Rebind();
  }
   else if (sourceAsICollectionView != null)
  {
   sourceAsICollectionView.Refresh();
  }

If the SourceCollection implements ICollectionView the grid will be refreshed using Refresh method. In addition RadGridView "listens" for CollectionChanged and responds for any change, so if you use ObservableCollection the grid will be automatically updated and no additional information will be required.

Please let me know if you need any further assistance.

Kind regards,
Tsvyatko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kennet
Top achievements
Rank 2
answered on 01 Jun 2010, 01:25 PM
Hi Tsvyatko,

First thanks for all help so far.

I'm trying "View.CollectionChanged" and I get a raised event everytime the grid wants new data, but "e.NewItems" is null (oldItems also null, and indexes -1) "e.Action" is "Reset"

I set subscribe to CollectionChanged in "datagrid Loaded".

Or maybe there is a simpler solution. I'm happy with how move items in the grid works, I can use that.  But why I like to have a ObservableCollection is since my application change "status" on items in the grid (just a int value) I don't want to ReBind the grid for that (takes to long time on large data).  So maybe I can change data on a cell manually ?  Or can I ReBind just selected rows?


*** EDIT ***

I think I got a solution for updateing my "status". I did not know that I could update the objects in the view (SampleData), but the grid updates when I change tha object manualy, just like a ObservableCollection.

*** EDIT ***


/Ken
0
Kennet
Top achievements
Rank 2
answered on 08 Jun 2010, 03:31 PM
Hi Tsvyatko,

I still have some issues with my reorder. I have added dragdrop from a second RadGrid, and insert to the database I use "InsertOnSubmit", that works. but I also need to change "display order" in my db and some other fields.
But .Rebind() don't work for me when I update the database outside my application.

Same with the demo app you did "159249-wpfapplication1.zip" if I change the data outside the app and run .Rebind() on the RadGrid, it's not updated.


Any suggestions, or more demos.  See it as one RadGrid as a library with sogns and a one RadGrid as a playlist. Where songs from the library can be drag dropped, also I can reorder items in the playlist grid by dragdrop (no reorder in library grid).

Regards
Kennet

0
Tsvyatko
Telerik team
answered on 10 Jun 2010, 04:16 PM
Hi Kennet,

In order to get the data from the database you can turn off the tracking of the object in the grid with endless paging using the following code:
this.linqDataContext.ObjectTrackingEnabled = false;

If you have any other questions do not hesitate to contact us.

Kind regards,
Tsvyatko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Kennet
Top achievements
Rank 2
Answers by
Tsvyatko
Telerik team
Kennet
Top achievements
Rank 2
Share this question
or