Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DisplayAttribute.Order in Derived class

DisplayAttribute.Order in Derived class

Scheduled Pinned Locked Moved C#
wpfwcfhelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gilbert Consellado
    wrote on last edited by
    #1

    class Base
    {
    [Display(Order = 0)]
    public int FirstProp {get;set;}

    [Display(Order = 1)]
    publuc string SecondProp {get; set;}
    }

    class Derived : Base
    {
    [Display(Order = 2)]
    public string ThridProp {get;set;}
    }

    I was expecting that the properties will have an order like this | FirstProp | SecondProp | ThirdProp | But I was getting like this | ThridProp | FirstProp | SecondProp | What was i missed? BTW i was binding it in a gridview. I will appreciate for any help will come. Thank you

    P L 2 Replies Last reply
    0
    • G Gilbert Consellado

      class Base
      {
      [Display(Order = 0)]
      public int FirstProp {get;set;}

      [Display(Order = 1)]
      publuc string SecondProp {get; set;}
      }

      class Derived : Base
      {
      [Display(Order = 2)]
      public string ThridProp {get;set;}
      }

      I was expecting that the properties will have an order like this | FirstProp | SecondProp | ThirdProp | But I was getting like this | ThridProp | FirstProp | SecondProp | What was i missed? BTW i was binding it in a gridview. I will appreciate for any help will come. Thank you

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      I'm not familiar with the GridView, but the behaviour looks like its started with fields in the derived class before moving onto the base class. If that's the case, that's a pretty dumb implementation.

      G 1 Reply Last reply
      0
      • P Pete OHanlon

        I'm not familiar with the GridView, but the behaviour looks like its started with fields in the derived class before moving onto the base class. If that's the case, that's a pretty dumb implementation.

        G Offline
        G Offline
        Gilbert Consellado
        wrote on last edited by
        #3

        What is your suggestion? Actually i am just using auto-implemented property and i am not using any fields.

        1 Reply Last reply
        0
        • G Gilbert Consellado

          class Base
          {
          [Display(Order = 0)]
          public int FirstProp {get;set;}

          [Display(Order = 1)]
          publuc string SecondProp {get; set;}
          }

          class Derived : Base
          {
          [Display(Order = 2)]
          public string ThridProp {get;set;}
          }

          I was expecting that the properties will have an order like this | FirstProp | SecondProp | ThirdProp | But I was getting like this | ThridProp | FirstProp | SecondProp | What was i missed? BTW i was binding it in a gridview. I will appreciate for any help will come. Thank you

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Gilbert Consellado wrote:

          What was i missed?

          Make the properties virtual, override them in the derived class, add the attribute. Yes, that's more work, but it is also more logical.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          G 1 Reply Last reply
          0
          • L Lost User

            Gilbert Consellado wrote:

            What was i missed?

            Make the properties virtual, override them in the derived class, add the attribute. Yes, that's more work, but it is also more logical.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            G Offline
            G Offline
            Gilbert Consellado
            wrote on last edited by
            #5

            Yeah you're right. But in msdn documentation that DisplayAttribute.Order[^] can change the order of the properties. And i tried it but no success.

            L 1 Reply Last reply
            0
            • G Gilbert Consellado

              Yeah you're right. But in msdn documentation that DisplayAttribute.Order[^] can change the order of the properties. And i tried it but no success.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Gilbert Consellado wrote:

              But in msdn documentation that DisplayAttribute.Order[^] can change the order of the properties.

              You mean it does not work if you mirror the properties in the derived class?

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              G 1 Reply Last reply
              0
              • L Lost User

                Gilbert Consellado wrote:

                But in msdn documentation that DisplayAttribute.Order[^] can change the order of the properties.

                You mean it does not work if you mirror the properties in the derived class?

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                G Offline
                G Offline
                Gilbert Consellado
                wrote on last edited by
                #7

                Yes, its is

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups