AutoGeneratedField attribute to false

6 posts, 0 answers
  1. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 16 Oct 2010 Link to this post

    I have this :

    [Display(AutoGenerateField = false)]
    [DataMember(Order = 0)]
    public int CustomerId
    {
        get { return _CustomerId; }
        set { _CustomerId = value; }
    }

    But I still see my column in the grid.  Is there something I'm unaware of ?
    However, the order attribute works, also on the Silverlight forum many people claim that this works with the DataGrid

    I'm wondering what's wrong.

    The AutoGeneratedColumns is true of course.
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Oct 2010 Link to this post

    Hello Marc Roussel,

    I was not able to reproduce the problem with the latest official version. Please find attached a sample project.
    Note that the Players column is not shown because its AutoGenerateField attribute is set to false.

    Alternatively, you can subscribe to the AutoGeneratingColumn event of the RadGridView and cancel it for the column you want not to be shown.

    Regards,
    Veselin Vasilev
    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
  3. DevCraft banner
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2010 Link to this post

    Hi,

    I've looked at your projet and it isn't the same as mine, mine is using WCF and my class is a DataContract which each property is a DataMember using the [DataMember] Attribute.

    And your project doesn't look like a normal Client-Server application as there's no Application.Web server side to get the data from WCF.  Could you try a simple Client-Server architecture and test with a simulated WCF scenario ?
  5. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2010 Link to this post

    Here's a class for you to test

    using System; 
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Configuration;
    using System.ComponentModel.DataAnnotations;
      
    namespace Application.Web
    {
        [DataContract]
        public class Customer
        {
            #region ' Fields '
            private int _CustomerId;
            private string _Name;
            private string _Phone;
            private string _ConnectionInformation;
            private string _Note;
            private DateTime _CreatedDate;
            private int _PlatformId;
            private string _PlatformVersion;
            private string _PlatformPatch;
            private string _Message;
            #endregion
      
            #region ' Properties '
            [Display(AutoGenerateField = false)]
            [DataMember(Order = 0)]
            public int CustomerId
            {
                get { return _CustomerId; }
                set { _CustomerId = value; }
            }
            [Display(AutoGenerateField = true)]
            [DataMember(Order = 1)]
            public string Name
            {
                get { return _Name; }
                set { _Name = value; }
            }
            [Display(AutoGenerateField = true)]
            [DataMember(Order = 2)]
            public string Phone
            {
                get { return _Phone; }
                set { _Phone = value; }
            }
            [Display(AutoGenerateField = false)]
            [DataMember(Order = 7)]
            public string ConnectionInformation
            {
                get { return _ConnectionInformation; }
                set { _ConnectionInformation = value; }
            }
            [Display(AutoGenerateField = false)]
            [DataMember(Order = 8)]
            public string Note
            {
                get { return _Note; }
                set { _Note = value; }
            }
            [Display(AutoGenerateField = true)]
            [DataMember(Order = 9)]
            public DateTime CreatedDate
            {
                get { return _CreatedDate; }
                set { _CreatedDate = value; }
            }
            [Display(AutoGenerateField = true)]
            [DataMember(Order = 3)]
            public int PlatformId
            {
                get { return _PlatformId; }
                set { _PlatformId = value; }
            }
            [Display(AutoGenerateField = true)]
            [DataMember(Order = 4)]
            public string PlatformVersion
            {
                get { return _PlatformVersion; }
                set { _PlatformVersion = value; }
            }
            [Display(AutoGenerateField = false)]
            [DataMember(Order = 5)]
            public string PlatformPatch
            {
                get { return _PlatformPatch; }
                set { _PlatformPatch = value; }
            }
            [Display(AutoGenerateField = false)]
            [DataMember(Order = 6)]
            public string Message
            {
                get { return _Message; }
                set { _Message = value; }
            }
            #endregion
        }
    }
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2010 Link to this post

    I did place a ticket with your project modified
    Let me know
  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 19 Oct 2010 Link to this post

    Hello Marc Roussel,

    I have already replied to your support ticket:

    It seems that the standard sdk's DataGrid control behaves the same way.
    Further, when I inspected the generated proxy code in the References.cs file I noticed that those attributes are not propagated:

    Copy Code
    [System.Runtime.Serialization.DataMemberAttribute(Order=1)]
    public int CustomerId {
        get {
            return this.CustomerIdField;
        }
        set {
            if ((this.CustomerIdField.Equals(value) != true)) {
                this.CustomerIdField = value;
                this.RaisePropertyChanged("CustomerId");
            }
        }
    }

    As you see, only the Order attribute is generated and not the AutoGenerateField.

    If you manually add the attribute there - it will work:

    Copy Code
    [System.Runtime.Serialization.DataMemberAttribute(Order=1)]
    [Display(AutoGenerateField=false)]
    public int CustomerId {
        get {
                return this.CustomerIdField;
            }
        set {
              if ((this.CustomerIdField.Equals(value) != true)) {
                   this.CustomerIdField = value;
                   this.RaisePropertyChanged("CustomerId");
                 }
            }
    }

    The problem here is that this is an auto-generated code and can be overridden the next time you update the service reference.


    Best wishes,
    Veselin Vasilev
    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
Back to Top
DevCraft banner