Sorting in DataGridView

Posted on 2010-01-12
Medium Priority
Last Modified: 2013-12-17

i am binding ListDatasource to datagridview as follows.

List<Request> lstRequests = new List<Request>
lstRequests. AddRange(m_oRequests.Cast<Request>());
dgv_requests.DataSource = lstRequests;

How apply sorting on the datagridview.


Question by:shore-support
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 26300251
LVL 30

Expert Comment

ID: 26300571
The question is not very clear - what's the problem?

Did you try DataGridView.Sort method?

Check details here:

LVL 30

Expert Comment

ID: 26300589
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.


Author Comment

ID: 26302597
none of the aboc=ve comments are useful for me.

can any give the code for sorting winforms datagidview.

DataSource  to my DataGridView is List<object> or IBincingList<object>

LVL 30

Accepted Solution

anarki_jimbel earned 1500 total points
ID: 26307791
Shashi, I believe above links might be useful - the question is how to apply. Ind you need to realize yourself what do you need.

What is sorting? You compare objects of some specific type and put them in some specific order.
If you have (as from you last post) a list of objects (List<object>) how you think you may sort them? Ther is no Compare method for <object> type. Therefore we can't talk about sorting at all. If we sort strings we compare characters inside the strings, if we sort numbers - we compare numbers. But how you want to sort generic objects.
Therefore, you need objects of some specific type. These objects need to have Compare method. Then you  can use approaches listed above.

By the way, the List class has the Sort method, you may use it before making the list a DataSource. But again - objects have to be comparable.

Author Closing Comment

ID: 31676093

Featured Post

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question