Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:22:28+00:00 2026-05-10T23:22:28+00:00

Using an ORM approach in applications can often lead to the scenario where you

  • 0

Using an ORM approach in applications can often lead to the scenario where you have a collection of objects you’ve retrieved and would like to display them in a tabular view using a DataGridView.

In my (limited) experience, binding collections of objects using a custom BindingList to a DataGridView results in poor performance and unsatisfactory sorting. I’m looking for a generic solution to this problem such that it’s straightforward to populate a DataGridView and also extract the underlying objects later.

I will describe a good solution I’ve found, but I’m looking for alternatives.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:22:28+00:00Added an answer on May 10, 2026 at 11:22 pm

    I am going to preface this answer with the statement that my experience is within the 2.0 Framework domain. The newer Frameworks may offer other solutions.

    Below is a BindingList derived class that supports bi-directional sorting and other useful features of List. I can’t take credit for the PropertyComparer sorting. I found this in an article a while back, but now I see it is all over the Internet so I unfortunately cannot cite the original source.

    Another alternative is the BindingListView: http://blw.sourceforge.net. This class allows you to create a view of a List collection, like you would with a DataTable object, including the ability to define a Filter and a Sort.

    public class UsefulBindingList<T> : BindingList<T> {     private bool _isSorted = false;     private ListSortDirection _sortDirection;     private PropertyDescriptor _sortProperty;      protected override bool SupportsSortingCore     {         get { return true; }     }      protected override bool IsSortedCore     {         get { return _isSorted; }     }      protected override ListSortDirection SortDirectionCore     {         get { return _sortDirection; }     }      protected override PropertyDescriptor SortPropertyCore     {         get { return _sortProperty; }     }       public void AddRange(IEnumerable<T> collection)     {         IEnumerator<T> e = collection.GetEnumerator();         while (e.MoveNext())         {             this.Add(e.Current);         }     }      public T Find(Predicate<T> match)     {         List<T> items = this.Items as List<T>;         if (items != null)             return items.Find(match);         else             return default(T);     }      public int FindIndex(Predicate<T> match)     {         List<T> items = this.Items as List<T>;         if (items != null)             return items.FindIndex(match);         else             return -1;     }      public bool Exists(Predicate<T> match)     {         List<T> items = this.Items as List<T>;         return items.Exists(match);     }      public void Sort()     {         List<T> items = this.Items as List<T>;         if (items != null)             items.Sort();     }      public void Sort(Comparison<T> comparison)     {         List<T> items = this.Items as List<T>;         if (items != null)             items.Sort(comparison);     }      public void Sort(IComparer<T> comparer)     {         List<T> items = this.Items as List<T>;         if (items != null)             items.Sort(comparer);     }      protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)     {         _sortProperty = prop;         _sortDirection = direction;          List<T> items = this.Items as List<T>;         if (items != null)         {             PropertyComparer<T> pc = new PropertyComparer<T>(prop, direction);             items.Sort(pc);             _isSorted = true;         }         else         {             _isSorted = false;         }         this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));     }      protected override void RemoveSortCore()     {         _isSorted = false;     }  }  public class PropertyComparer<T> : IComparer<T> {     private ListSortDirection _sortDirection;     private PropertyDescriptor _property;      public PropertyComparer(PropertyDescriptor property, ListSortDirection direction)     {         _property = property;         _sortDirection = direction;     }      public int Compare(T x, T y)     {         int rv = 0;         object vx = _property.GetValue(x);         object vy = _property.GetValue(y);         rv = System.Collections.Comparer.Default.Compare(vx, vy);         if (_sortDirection == ListSortDirection.Descending)             rv = -rv;         return rv;     }  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here are the URL components: http://www.example.com/en/public/img/logo.gif \__/ \_____________/\_____________________/ #1 #2… May 11, 2026 at 6:09 pm
  • Editorial Team
    Editorial Team added an answer See this thread on a Trolltech forum. (Well actually that's… May 11, 2026 at 6:09 pm
  • Editorial Team
    Editorial Team added an answer There's a fstat(2) function. NAME stat, fstat, lstat - get… May 11, 2026 at 6:09 pm

Related Questions

I have a large tree of Java Objects in my Desktop Application and am
I'm starting a new application and looking at using an ORM -- in particular,
It seems to me that introducing an ORM tool is supposed to make your
I'm a bit scared to ask this question as it may start a religous

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.