473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sort top X rows of DataGridView

4 New Member
Can any one tell me how to tweak the existing Sort method, in DataGridView Class, so as I can sort only certain top rows.

Say 5 rows.
And i want to sort only first 3 rows. Last 2 should be left, as such.

example: (row number followed by string)
1.C
2.A
3.B
4.E
5.D

the expected output:
1.A
2.B
3.C
4.E
5.D

Please help me, as I'm new to .Net
Dec 6 '08 #1
2 1998
kenobewan
4,871 Recognized Expert Specialist
I believe that you could do this via sql and have an exclusion criteria in your where clause. This may depend on the nature of your data, as you will still be effectively sorting the column just excluding the values in the other rows..
Dec 7 '08 #2
nukefusion
221 Recognized Expert New Member
Is your grid bound to a datasource? If so then you should perform the sort on the underlying datasource.
If not, you could indeed use the DataGridView.Sort() method. You would need to create a class that implements the IComparer interface. This interface has one method - Compare. Within that method you would compare two objects and return a result that specifies whether object A is less than, equal to, or greater than object B.
If you're only trying to sort A's B's and C's then this might be feasible, however, if you want to sort a large range of values you're custom sorting code might become quite substantial.
How large is the range of expected values in your column?
Dec 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: thomasp | last post by:
I have a datagridview that allows the user to sort the column by clicking on the header of the column the user wishes to sort. I did not code this, it had the ability when the datagrid was...
1
by: inpuarg | last post by:
Is it possible to disable sort temporarilty ? without changing current row ? I want to add a row to a specific location. But if user sorted the datagridview row goes to a wrong position. That 's...
1
by: Luca Beretta | last post by:
I think this a simple question but i'm breaking my brain without results. I've a datagridview bounded to a datatable, with an imagecolumn that should contain a different bitmap depending from a...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
3
by: joey.powell | last post by:
I have a datagridview where I set its "DataSource" property to a DataSet and its "DataMember" property to a table within the DataSet. I need for the DataGridView to "sort" through the contents of...
2
by: Rick | last post by:
VS 2005/Pro I'm using a DataGridView in a Windows form and allowing the user to sort the columns by clicking on the header column. Is there some method offered by the grid to return back to...
4
by: Vidhura | last post by:
This article explains how to make all the rows height the same in DataGridView in .Net 2.0 while using AutoSizeRowMode In DataGridView 2.0,there is a option to resize row to fit the content of...
4
by: NvrBst | last post by:
I have a log viewer. I sort the DataGridView by the Time Column and then run a function to set all cell backcolors depending if the cell above is different. This works correctly, however, when...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.