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
  • 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.


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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

621 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