GridViewDataColumn Header from RIA MetaData?

26 posts, 1 answers
  1. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 31 Aug 2009 Link to this post

    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
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Sep 2009 Link to this post

    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.
  3. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 01 Sep 2009 Link to this post

    Hi Vlad,

    Excellent--thanks for the quick response!

    Scott
  4. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 06 Sep 2009 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Sep 2009 Link to this post

    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.
  6. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 07 Sep 2009 Link to this post

    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




  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Sep 2009 Link to this post

    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.
  8. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 08 Sep 2009 Link to this post

    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


  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Sep 2009 Link to this post

    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.
  10. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 13 Sep 2009 Link to this post

    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
  11. Kasimier Buchcik
    Kasimier Buchcik avatar
    3 posts
    Member since:
    Oct 2009

    Posted 18 Oct 2009 Link to this post

    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
  12. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 22 Oct 2009 Link to this post

    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.
  13. Kasimier Buchcik
    Kasimier Buchcik avatar
    3 posts
    Member since:
    Oct 2009

    Posted 28 Oct 2009 Link to this post

    Sounds great!
    Regards & thanks,
    Kasimier
  14. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 25 Jan 2010 Link to this post

    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
  15. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 28 Jan 2010 Link to this post

    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.
  16. Kasimier Buchcik
    Kasimier Buchcik avatar
    3 posts
    Member since:
    Oct 2009

    Posted 29 Jan 2010 Link to this post

    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
  17. KOG
    KOG avatar
    5 posts
    Member since:
    Dec 2009

    Posted 23 Feb 2010 Link to this post

    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

  18. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 24 Feb 2010 Link to this post

    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.
  19. KOG
    KOG avatar
    5 posts
    Member since:
    Dec 2009

    Posted 24 Feb 2010 Link to this post

    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
  20. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 26 Apr 2010 Link to this post

    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.
  21. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 26 Apr 2010 Link to this post

    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.
  22. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 26 Apr 2010 Link to this post

    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.
  23. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 26 Apr 2010 Link to this post

    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.
  24. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 26 Apr 2010 Link to this post

    I just tested it and everything is working great! Thank you very much!! :)
  25. Chris Howle
    Chris Howle avatar
    3 posts
    Member since:
    Jul 2009

    Posted 19 Mar 2012 Link to this post

    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.
  26. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Mar 2012 Link to this post

    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 >>
Back to Top