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

[Solved] Issues regarding RadGridView, Column Headers and DisplayAttribute

2 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Manuel Felício
Top achievements
Rank 1
Manuel Felício asked on 27 Jan 2010, 12:53 PM
It sounds great but it's not working like MS Datagrid, at least not in my version (using SP2).

I'm binding my itemssource property to a collection that implements IEnumerable<T>, ICollectionView. The items in the collection have DisplayAttribute on each property.

When the collection is empty (not null, just empty) no headers are displayed. If i add an item to the collection then the headers are displayed. I inspected your code using reflector and I've seen that the first you do when the ItemsSourceProperty changes is to check if it is an ICollectionView and if it's empty. If so, you register on the CollectionChanged event and don't care about the collection anymore until that event fires..which is wrong. You should always check if the collection implements IEnumerable<T> and get the <T> out of it to query for DisplayAttributes in the fields.

Another interesting thing is that even if the source collection really is empty but the ICollectionView.IsEmpty property returns false the RadGridView displays headers as expected.

I also noticed that the collection I bind to ItemsSource doesn't implement ICollectionView (just IEnumerable<T>) then it works as expected, so it's an ICollectionView handling issue.

On a side note..I also noticed that the RadGridView doesn't query the ICollectionView.CanSort property before querying the ICollectionView.SortDescriptionCollection property. When I was testing I had the SortDescriptioncollection property returning null and the CanSort return false. An exception was thrown because you tried to register via reflection in the CollectionChanged event without checking if the SortDescriptionCollection returned by the ICollectionView was null.

I'm attaching a sample solution so you can see what I'm talking about. I couldn't attach the solution here so I used megaupload for that..sorry.

http://www.megaupload.com/?d=XA0YCK2J

If you don't wanna open it at least see a screenshot of the sample running.



Best regards,

Manuel FelĂ­cio

2 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 02 Feb 2010, 09:29 AM
Hi Manuel,

I have explained previously why we currently have this issue in this forum thread. It is just this case when you have implemented IEnumerable<T> in your collection. If you did not implement this interface the toolkit's DataGrid will also not able to generate its columns when the collection is empty. We will do our best to address this issue for our next major release - Q1 2010 targeted for the first half of March.

We explicitly did not query the CanSort property, because there are collections out there (specifically those in RIA Services) which return false before they have some entities, and then magically return true without raising property change for CanSort property. Regarding your implementation it is best if you return an empty collection instead of null. It is a best practice to always return empty collections for your public properties instead of nulls. As for the exception we have already fix it in our code.

Thanks for your feedback. It is greatly appreciated.

All the best,
Stefan Dobrev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Manuel Felício
Top achievements
Rank 1
answered on 02 Feb 2010, 10:23 AM
Hi Stefan,

I know you already answered it in another thread but I started this thread before your answer. I did this because I thought you wouldn't notice my other post, since it was in a thread that was already marked as Answered.

Anyway, it's good to know that you guys are trying to address this issue in the upcoming release. I'm very thankful!

Best regards,

MF.
Tags
GridView
Asked by
Manuel Felício
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Manuel Felício
Top achievements
Rank 1
Share this question
or