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

GridViewDataColumn Header from RIA MetaData?

25 Answers 342 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.
Scott
Top achievements
Rank 1
Scott asked on 01 Sep 2009, 04:50 AM
Hi All,

Is there currently (or will there be in the future) support for a GridViewDataColumn populating its Header from the System.ComponentModel.DataAnnotations.DisplayAttribute which adorns an Entity's properties in the metadata "buddy" class in a RIA Service implementation?

I'm just getting familiar with the RadGridView, so sorry if I've overlooked something obvious.

Cheers,
Scott

25 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 01 Sep 2009, 09:31 AM
Hello Scott,

This will be available in our next internal build (this Friday).

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott
Top achievements
Rank 1
answered on 01 Sep 2009, 09:27 PM
Hi Vlad,

Excellent--thanks for the quick response!

Scott
0
Scott
Top achievements
Rank 1
answered on 07 Sep 2009, 02:52 AM
Hi Vlad,

I see that Build 2_904 has DisplayAttribute support for auto-generated columns--thanks. Any chance you will add this for explicitly-defined (in XAML at least) columns?

Cheers,
Scott
0
Vlad
Telerik team
answered on 07 Sep 2009, 06:44 AM
Hello Scott,

This was implemented exactly in the same way as in standard MS DataGrid and will work only for auto-generated columns. With declared column in XAML or dynamic columns creation you have full control to specify the column header using Header property.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott
Top achievements
Rank 1
answered on 07 Sep 2009, 10:18 PM
Hi Vlad,

Yes, if your grid is implemented the same way as the MS SL3 RTM DataGrid, that will be excellent. The MS DataGrid code in the snippet below results in the Headers automatically being populated from the DisplayAttribute in our meta data--no Header="..." required. We are going to generate meta data from a localised meta-data provider, and the auto-populated Header behaviour would greatly reduce the number of places we need to explicitly provide a localised Header.

        <DataControls:DataGrid x:Name="ListDataGrid" 
 
                                ItemsSource="{Binding Path=BookingItemsSource}" 
 
                                SelectedItem="{Binding SelectedBooking, Mode=TwoWay}" 
 
                                Width="Auto" 
 
                                Height="Auto" 
 
                                AutoGenerateColumns="False" 
 
                                SelectionMode="Single" 
 
                                HeadersVisibility="All" 
 
                                CanUserResizeColumns="True" 
 
                                CanUserReorderColumns="True" 
 
                                CanUserSortColumns="True" 
 
                                HorizontalScrollBarVisibility="Auto" 
 
                                VerticalScrollBarVisibility="Visible" 
 
                                VerticalContentAlignment="Top" 
 
                                IsReadOnly="True" 
 
                                > 
 
            <DataControls:DataGrid.Columns> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding book_id}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding book_summary}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding book_start}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding book_end}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding Job}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding CostCentre}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding Priority}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding book_actual_end}" /> 
 
                <DataControls:DataGridTextColumn  Binding="{Binding Address}" /> 
 
            </DataControls:DataGrid.Columns> 
 
 
        </DataControls:DataGrid> 
 

Cheers,
Scott




0
Vlad
Telerik team
answered on 08 Sep 2009, 06:01 AM
Hello Scott,

I've tried MS DataGrid with declared columns however this didn't worked for me - I've attached small project.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott
Top achievements
Rank 1
answered on 08 Sep 2009, 10:48 PM
Hi Vlad,

Interesting! It appears to be the DomainDataSource that makes the difference. If you bind the DataGrid's ItemsSource directly to the RIA DomainContext's .Customers (EntityList<Customer>) property (as we are doing in our solution using a MVVM pattern), the Headers get auto-populated from the DisplayAttribute. If the DataGrid is bound to an intermediate DomainDataSource, the Headers are lost.

I've updated your sample project with a example of what I mean. Can I upload here?

Basically the altered sample looks like this:

MainPage.xaml (Note the DataGrid1.ItemsSource binding):
<UserControl x:Class="SilverlightApplication.MainPage" 
 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
 
    xmlns:web="clr-namespace:WebApplication" 
 
    xmlns:ria="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls" 
 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
 
    xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
 
    xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
 
    <Grid x:Name="LayoutRoot"
 
<!--        <ria:DomainDataSource x:Name="DomainDataSource1" AutoLoad="True" QueryName="GetCustomers">--> 
 
<!--            <ria:DomainDataSource.DomainContext>--> 
 
<!--                <web:DomainService1 />--> 
 
<!--            </ria:DomainDataSource.DomainContext>--> 
 
<!--        </ria:DomainDataSource>--> 
 
 
 
        <data:DataGrid x:Name="DataGrid1" ItemsSource="{Binding Customers, Mode=OneWay}" 
 
 Width="Auto" Height="Auto" AutoGenerateColumns="False" SelectionMode="Single" HeadersVisibility="All"  
 
 CanUserResizeColumns="True" CanUserReorderColumns="True" CanUserSortColumns="True" HorizontalScrollBarVisibility="Auto"  
 
 VerticalScrollBarVisibility="Visible" VerticalContentAlignment="Top" IsReadOnly="True"
 
            <data:DataGrid.Columns> 
 
                <data:DataGridTextColumn Binding="{Binding Address}" /> 
 
                <data:DataGridTextColumn Binding="{Binding City}" /> 
 
            </data:DataGrid.Columns> 
 
        </data:DataGrid> 
 
    </Grid> 
 
</UserControl> 
 

MainPage.xaml.cs:

namespace SilverlightApplication 
 
 
    public partial class MainPage : UserControl 
 
    { 
 
        private WebApplication.DomainService1 _domainServiceClient; 
 
 
 
        public MainPage() 
 
        { 
 
            InitializeComponent(); 
 
            _domainServiceClient = new WebApplication.DomainService1(); 
 
 
 
            DataContext = _domainServiceClient; 
 
            _domainServiceClient.Load(_domainServiceClient.GetCustomersQuery()); 
 
        } 
 
    } 
 
 

So I know it would make us happy if the RadGridView worked as the DataGrid does above, but I don't know how many others will use it in this way (binding directly to EntityList). Let me know if you want to see the whole modified test solution.

Cheers,
Scott


0
Vlad
Telerik team
answered on 11 Sep 2009, 09:03 AM
Hi Scott,

Display attribute support for declared columns will be available in our latest internal build (today).

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott
Top achievements
Rank 1
answered on 14 Sep 2009, 03:40 AM
Hi Vlad & Team,

The new build works like a charm. Thanks very much for the prompt and helpful support. Keep up the great work!

Scott
0
Kasimier Buchcik
Top achievements
Rank 1
answered on 18 Oct 2009, 06:14 PM
How was this implemented by Telerik? Does is retrieve the [Display] information of a relevant property via an instance of the object in context? If yes, then this has the same flaw as the default DataForm in Silverlight: If there is no instance, i.e. if the collection bound to the grid is empty, then there won't be any column headers displayed. The same goes for the DataForm: it becomes quite invisible, when there's no instance to bind to. This constitutes a major UI flaw - but I don't know how to fix this either, without resorting to explicitely binding the headers to localized resources.

Regards,
Kasimier
0
Stefan Dobrev
Telerik team
answered on 22 Oct 2009, 09:23 AM
Hello Kasimier,

We try to resolve the type, which donates the attributes on several step. First we check to see if you have passed a generic enumerable as ItemsSource if so we take its type. If the type is object (rear cases when you bind to IEnumerable<object>) we resolve the type from the first instance. If you have passed a non generic collection we also fall back to resolve the type from the first element.

Hope this helps.

Sincerely yours,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kasimier Buchcik
Top achievements
Rank 1
answered on 28 Oct 2009, 02:52 PM
Sounds great!
Regards & thanks,
Kasimier
0
Manuel Felício
Top achievements
Rank 1
answered on 25 Jan 2010, 11:31 AM
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 and IPagedCollectionView. The items in the collection are entities from WCF RIA Services and they have DisplayAttribute applied to its properties.

When the view loads the collection is empty (not null, just empty) and then I fetch my data asynchronously (using WCF RIA Services), the collection gets items added to it (INotifyCollectionChanged event fires) and only then the headers are displayed.

The problem is that (besides the delay when displaying the headers) is that in some cases I might not have data to display and the grid will not show any headers at all..

With MS Datagrid the headers are automatically displayed when the view loads, even if the collection is empty, so when my data is fetched the grid already has the headers displayed, even if there is no data to return.

I'd really like to know if I'm doing anything wrong or if this is supposed to work with empty collections.

Best regards,

Manuel Felício
0
Stefan Dobrev
Telerik team
answered on 28 Jan 2010, 11:25 AM
Hello Manuel,

You have hit a corner case. The problem is that when RadGridView is bound to IPagedCollectionView it delays its columns creation until there are items in the view. We do this because we will generate columns based on the first item type in the view. However in your case we can generate columns based on the generic type of your collection, bypassing the IPagedCollectionView. We will do our best to change this behavior in one of the next internal builds of the control.

Thanks for pointing out this issue. I have updated your Telerik points.

All the best,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kasimier Buchcik
Top achievements
Rank 1
answered on 29 Jan 2010, 04:29 PM
Thank you Manuel for reporting this.
I'm not yet using Telerik's stuff so great to know that this will also work with the RadGridView in the (hopefully) near future.

Regards,
Kasimier
0
KOG
Top achievements
Rank 1
answered on 23 Feb 2010, 11:58 PM
Stefan,
Have an observation similar to Manuel's... and a question. Two-way binding is in place on a collection in a telerikGrid in our Silverlight app.

We use 3 lines to bind (this will be a VB rendering): 

 


Dim
oCollectionViewSource As New Data.CollectionViewSource

 

oCollectionViewSource.Source = our_collection

grdShowCollection.ItemsSource = oCollectionViewSource.View

The grid has a dropdown but that is working fine. You called Manuel's description a corner case.

If the collection is empty, we cannot insert items into the grid that does not break the two-way binding. Is there a way to preserve the two-way binding and insert a blank row into the grid when the Source of CollectionViewSource is empty?

Keefe

0
Stefan Dobrev
Telerik team
answered on 24 Feb 2010, 09:56 AM
Hello Keefe,

I'm not sure that I can understand your scenario thoroughly. Can you please open a new support ticket and attach your application there?

Best wishes,
Stefan Dobrev
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
KOG
Top achievements
Rank 1
answered on 24 Feb 2010, 10:42 PM
Stefan,

Thanks for your quick response. We have solved our issue and we wanted to spare others the effort by discussing the technique here. It applies to Manuel's question as well. The code we offered earlier in the thread worked for a two-way binding of a collection to a grid object, but seemed not to work when the collection was empty.

In our example we have a combo and a textbox inside our telerik grid. The combo binds a collection wonderfully using the telerik controls and the methods described. But if the collection were empty how would we preserve two-way binding and get our control to recognize new items. The clue was given by Manuel himself, although he was concerned about auto-generating the headers. When the INotifyCollectionChanged event is wired up correctly in the objects behind it will 'wake up' the control when you add a stub member to the underlying collection. All you have to do is determine the default values for the collection members and add an object to the collection. The control recognizes the internal binding and restores the column integrity (or the headers), keeping the two-way binding. This is great when several events are adding and removing items from collections that affect this collection, because you can be sure that the grid will always have the latest contents.

We spent 3 peoples' work of 2 days effort to get this right! The first big step was getting to the CollectionViewSource and understanding that implementation completely; the second was wiring up the INotifyCollectionChanged event to get the two-way binding in place and the third was realizing that if the wire-up were correct, the collection would force the controls to respond.

Hope this helps others.

Keefe
0
Manuel Felício
Top achievements
Rank 1
answered on 26 Apr 2010, 11:14 AM
Is this fixed yet? The bug was column headers not being set automatically with DisplayAttribute when the collection implemented ICollectionView, IEnumerable<T> and was empty.

Thanks.
0
Rossen Hristov
Telerik team
answered on 26 Apr 2010, 11:45 AM
Hello Manuel Felício,

If this is the same as this PITS issue, then it was fixed. But I am not sure that it is the same.

I would strongly recommend downloading the latest version (it's free)  and testing against your specific scenario.

Please, let us know if problems still occur. It would be even better if you send us your sample project, since you might have hit another bug that is different from the one above.

Thank you in advance.

Sincerely yours,
Ross
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
Manuel Felício
Top achievements
Rank 1
answered on 26 Apr 2010, 12:16 PM
Hi, nope it's not that one.

The issue I'm talking about is this: http://www.telerik.com/community/forums/silverlight/gridview/issues-regarding-radgridview-column-headers-and-displayattribute.aspx . ColumnHeaders, DisplayAttribute, ICollectionView and IEnumerable<T>. Its an old issue that I've been tracking since Q3.

Best regards,

MF.
0
Rossen Hristov
Telerik team
answered on 26 Apr 2010, 12:30 PM
Hello Manuel Felício,

Just to make sure, could you simply try your project with the latest version -- 2010 Q1 SP1.

Let us know if your project is still not working.

Greetings,
Ross
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
Manuel Felício
Top achievements
Rank 1
answered on 26 Apr 2010, 03:33 PM
I just tested it and everything is working great! Thank you very much!! :)
0
Chris Howle
Top achievements
Rank 1
answered on 19 Mar 2012, 03:18 PM
Does this only work with the Silverlight version of the controls? I'm trying to get this to work with the latest WPF RadGridView, and have a collection of object with DisplayAttribute set, and the collection supports IEnumerable<T> and ICollection<T>.

I have noticed that this appears to not work on the sample application for WPF or Silverlight (http://www.telerik.com/help/silverlight/gridview-columns-defining-columns.html ) .  I'm trying to get this example to work, following forum posts that indicate that it is now fixed.

I'f it is working, could you please post some sample code.

Regards,

Chris.
0
Vlad
Telerik team
answered on 19 Mar 2012, 03:22 PM
Hello,

 This is available for WPF 4 version of our assemblies as well. Please make sure that you are using our .NET 4 version!

Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Scott
Top achievements
Rank 1
Kasimier Buchcik
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Manuel Felício
Top achievements
Rank 1
KOG
Top achievements
Rank 1
Rossen Hristov
Telerik team
Chris Howle
Top achievements
Rank 1
Share this question
or