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

Place Holders

4 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 13 Oct 2010, 07:06 AM
What is the best way to put place holders into a bindable collection?
My collection uses these interfaces:
ICollectionView, IEnumerable, INotifyCollectionChanged, IEditableCollectionView, IPagedCollectionView, INotifyPropertyChanged

(And the "real" objects in the collection are entities e.g. Car entity)


At first, I made my collection return null at the place holders, however this results in a non visible element in the table, further more, when a null item was replaced with an actual item, the telerik gridview is not handling the CollectionChanged(replace, null -> Car)
i.e. Instead of going from 3 loaded +1 placeholder -> 4 loaded
It goes from 3  + 0 (you can't see the place holder) -> to 3
However, the moment you do something to the control (e.g. move a scroll bar, make it non visible then re visible again etc.) it will redraw the control correctly and show all 4 items. (The only way I've managed to counter this flaw, is if the collectionchanged.action == replace, and olditems.contains a placeholder, I rethrow a collectionreset, but this does seems like a flaw in the telerik controls)
Also, this can crash if my collection has sorts/filters, as it tries to filter the null and gives a null object exception



My second attempt was to have a PlaceHolder object. However, if I sort/filter again the gridview, it will crash and say that the property does not exist.




(Note in all the above examples, I'm adding sorts to my Collections SortDescriptions, not by clicking the grid)

4 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 14 Oct 2010, 12:53 PM
Hi Alex,

 Perhaps you're trying to implementing something close to our VirtualQueryableCollectionView. You can learn more about it here.

Kind regards,
Yavor Georgiev
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
Alex
Top achievements
Rank 1
answered on 14 Oct 2010, 01:13 PM
Yes, like that. I had essentially rebuilt a DomainDataSource from the ground up to try and achieve this. Out of curiosity, how does the Queryable collection view create the placeholders, with out crashing the gridview (i.e. mine crashes if I return null, with a null error, or with a property not found, if I return some other unexpected-object that does not have the expected properties)
0
Alex
Top achievements
Rank 1
answered on 18 Oct 2010, 02:33 AM
Ok I've played around with the Virtual Queryable Collection View,


How does the gridview know to NOT sort the items, when it is bound to a Virtual Queryable Collection View? (as this would probably solve all my problems)
i.e. I want the UI to be user-sortable, but I don't want the grid to actually sort my items, I just want it to signal the collection of the new sort descriptors, and and the collection will sort it self out.









The exact problems I'm having are as follows:

Background Information
I have created a ContextDataView<TEntity>
Which has Property ContextDataView<TEntity>, I have a grid bound to this DataView property. The dataview is a custom collection built from the ground up. It is essentially a PagedCollectionView with a custom source behind it
Behind the ContextDataView I have a NamedList<TEntity> : ObservableCollection<object> (it is essentially a typed collection, + event bubbling + place holder capabilities) which provides either the entity, or null in all other cases

Basically it's like an observablecollection<object> + autoquerying (like a DomainDataSource)
(I use the generic parameter for misc internal uses)



The scenario I use to create the problem is like this:
On construction of this ContextData, I add a sort descriptor. And via autoload, it loads 4/8 entities (it would normally load 0-3, then 4-7, out of a total count of 8. But for testing I stop the second load so I can test the place holders)
(Initially the collection is of size 0) When the load completes, it puts in the 4 loaded entities, then it sees the load operations total count is 8, so it signals the DataView to resize to 8.
This then goes through all my custom collections where it eventually fills the collection with custom PlaceHolder objects. (To the enumerator, the placeholder object is null) It adds these in 1 at a time, and raises the collection changed event at each add.

I add a sort descriptor to my DataView when it is constructed

Scenario 1.
If I raise the collection added, with items added object[1] { placeholder } the following happens:
(remembering that enumerating will reveal placeholders as null)
It will throw this error when it adds the SECOND placeholder (the first adds, raises collection changed, then the second adds, raises the collection change and then the error is thrown)

Message:
Object reference not set to an instance of an object.
Stack:
   at Telerik.Windows.Data.QueryableCollectionView.AdjustCurrencyAndPrepareCollectionChangedArguments(AdjustedCollectionChangedInfo info)
   at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChangedWithAdjustedArgs(NotifyCollectionChangedEventArgs originalArguments, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
   at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at .........ContextData.ContextDataView`1.RaiseCollectionChanged(NotifyCollectionChangedEventArgs eventArgs)



Scenario 2
At first I thought this might happen as I signal that I'm adding placeholder, but enumerating wouldn't display it. So I changed the notification to show that it's adding null, same problem.

Scenario 3
I just throw a collection reset event instead. No exceptions, (none that the grid raise) but it is clearly not working, as it just shows 8 blank rows (4 of which have the triangle on the left hand side which is usually used to show null/highlighted row, the other 4 show nothing)




(If I don't add a sort descriptor, it works fine thou)
0
Yavor Georgiev
Telerik team
answered on 19 Oct 2010, 01:35 PM
Hello Alex,

 The VirtualQueryableCollectionView disregards the RadGridView's SortDescriptors. In order to sort using those descriptors, you need to handle the VQCV's ItemsLoading event like so in order to generate the proper IQueryable on the client (this sample uses DevForce as a data back-end, but the principle is the same):
void Setup()
}
     Data.ItemsLoading += (s, e) =>
     {
         LoadData(e.StartIndex, e.ItemCount);
     };
}
void LoadData(int startIndex, int itemCount)
{
    var query = (EntityQuery<Order_Detail>)Context.Order_Details.OrderBy(o => o.OrderID)
        .Where(Data.FilterDescriptors)
        .Sort(Data.SortDescriptors)
        .Skip(startIndex).Take(itemCount);
    query.ExecuteAsync().Completed += (s, e) =>
    {
        Data.Load(startIndex, e.Results);
    };
}

where Data is the VQCV.

 It would be best to use the final version of the VirtualQueryableCollectionView, instead of rolling your own, as the RadGridView is already optimized to work with VirtualQueryableCollectionView. You can also couple it with the upcoming RadDomainDataSource, which provides the best integration with RadGridView, RadChart, etc.

Sincerely yours,
Yavor Georgiev
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
Alex
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Alex
Top achievements
Rank 1
Share this question
or