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. Business Object Properties in Random Order

Business Object Properties in Random Order

Scheduled Pinned Locked Moved C#
questionwpfwcfbusinesstutorial
4 Posts 2 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.
  • T Offline
    T Offline
    Thomas Wells
    wrote on last edited by
    #1

    How can I control the order that my properties appear in the DataBindings BindingSource selection dialog? Sorted alphabetic would be nice. I have a business object that inherits from a bindingsource. Its properties appear to be in an apparent random order in the binding source selection dialog. For example when I'm selecting a property to bind to a text box text property.

    T 1 Reply Last reply
    0
    • T Thomas Wells

      How can I control the order that my properties appear in the DataBindings BindingSource selection dialog? Sorted alphabetic would be nice. I have a business object that inherits from a bindingsource. Its properties appear to be in an apparent random order in the binding source selection dialog. For example when I'm selecting a property to bind to a text box text property.

      T Offline
      T Offline
      tgrt
      wrote on last edited by
      #2

      I'm thinking you might be able to do something like that by inheriting from ExpandableObjectConverter. I'm not sure, but it'll give you something to try out.

      public class MyClass : ExpandableObjectConverter
      {
      // ... additional code including Name and Value properties

      public override bool GetPropertiesSupported(ITypeDescriptorContext context)
      {
      return true;
      }

      public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
      {
      PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value, attributes);
      return properties.Sort(new string[] {"Name", "Value"});
      }
      }

      T 1 Reply Last reply
      0
      • T tgrt

        I'm thinking you might be able to do something like that by inheriting from ExpandableObjectConverter. I'm not sure, but it'll give you something to try out.

        public class MyClass : ExpandableObjectConverter
        {
        // ... additional code including Name and Value properties

        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
        return true;
        }

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
        PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value, attributes);
        return properties.Sort(new string[] {"Name", "Value"});
        }
        }

        T Offline
        T Offline
        Thomas Wells
        wrote on last edited by
        #3

        That was just the lead that I needed. I'm inheriting from a bindingsource and it implements ITypedList which has the GetItemProperties function. I overrode that function and simply added .Sort to base.GetItemProperties(listAccessors) Thanks

        T 1 Reply Last reply
        0
        • T Thomas Wells

          That was just the lead that I needed. I'm inheriting from a bindingsource and it implements ITypedList which has the GetItemProperties function. I overrode that function and simply added .Sort to base.GetItemProperties(listAccessors) Thanks

          T Offline
          T Offline
          tgrt
          wrote on last edited by
          #4

          Excellent. That's much more elegant. I believe my suggestion was a carry-over from 1.0 days. I know I did something like that (probably for a property grid) a long time ago.

          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