473,606 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DatagridView, stop sorting, please


On my WinForm I have a DataGridView, which contains four columns and
four rows. The last row contains only a sum of the values of the cells
of the previous rows in column 3. The cells [3,0], [3,1], [3,2] are
empty ( [row,column] ).

[0,0]="Mr." ; [0,1]="Smith" ; [0,2]="David" ; [0,3]=1000
[1,0]="Mrs."; [1,1]="Fog" ; [1,2]="Denise" ; [1,3]=2000
[2,0]="Mr." ; [2,1]="Ranger"; [2,2]="Stuart" ; [2,3]=3000
[3,0]="" ; [3,1]="" ; [3,2]="" ;

The user clicks on the column header of col 1 and expects the datagrid
to be sorted. As SortMode is set to
DataGridViewCol umnSortMode.Pro grammatic for each column, I do the
sorting within the "dgrdDetails_Co lumnHeaderMouse Click" Event. Steps
are as follows:

- Deleting the row with the sum, which is row 3
- Initiating the sort by:
this.dgrdDetail s.Sort( this.dgrdDetail s.Columns[e.ColumnIndex],
ListSortDirecti on.Ascending ) ;

Afterwards I wanted to add the row with the sum. Due to the emtpy cell
in col 1, this row appears always as the first row. I recon that the
datagrid is in SortMode still.

So I tried the following right after "this.dgrdDetai ls.Sort" and
before adding the row with the sum:

for ( int g = 0; g <= this.dgrdDetail s.Columns.Count - 1 ; g ++ )
this.dgrdDetail s.Columns[g].SortMode =
DataGridViewCol umnSortMode.Not Sortable ;

Still my summation row appears as the first row. Also setting the
SortMode to "Programmat ic" showed any difference.

How can I stop the DataGridView from sorting?

Any hint is highly appreciated!.


Apr 7 '08 #1
6 4725
What is the datasource of the grid? DataTable/DataView?
BindingList<T>? non-bound?

And how aer you doing the sort?

Apr 8 '08 #2
Hi Marc

There is a dataTable which is bound to the datagridview.

The sorting is done as mentioned above:
"this.dgrdDetai ls.Sort( this.dgrdDetail s.Columns[e.ColumnIndex],
ListSortDirecti on.Ascending ) ; "


Apr 8 '08 #3
.... is there anybody who can give me a hint?


Apr 10 '08 #4
Can I check; is it correct that you simply want to keep the "sum" row at
the top (or bottom), and allow sorting of the other rows?
Apr 10 '08 #5
Hi Marc,

That is pretty much it! The summation should always stay at the bottom
of the datagrid.


Apr 10 '08 #6
Why didn't you just say so?


Apr 10 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column for that property 2) Add the column to the datagridview 3) Populate a BindingSource by adding all instances of the above mentioned class. 4) Assign the BindingSource to the datagridview's DataSource property
by: Chris Botha | last post by:
VS2005 and I have a DataTable displayed in a DataGridView that needs custom sorting, with the DataSource of the grid set to the DataTable and the SortCompare event just won't fire. Then I found this in the docs "This event occurs only when the DataSource property is not set and the VirtualMode property value is false" This seems really odd but may be true. I can't see what the purpose of this event is then, how else will one use the...
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 tell me if this is even possible, and if so, how to do it? If this is completely impossible, how would you suggest going about sorting a ComboBox wherein the text displayed in the column is the client's name, and the underlying value is an ID? ...
by: Rainer Queck | last post by:
Hi NG, Why is it, that in my DataGridView all columns which are not bound to a "DataProperty" loos thier content in a couple of occasions? This happens if: - Underlaying DataSet.AcceptChanges() - DataGridView bound columns -Click on header for sorting Is there a event, that I can use to detect this situation and then
by: mahesh.nimbalkar | last post by:
I want to use Multi column sorting in DataGridView. The scenario is like this: 1) DataGridView has two columns; Id and name 2) User clicks on Id column and DataGridView is sorted ascending 3) User clicks on Id column and DataGridView is sorted descendin Now, when user clicks on name column, the DataGridView should be sorted as Id desc and name asc.
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a DataGridView on a Form. I want to disable the clicking on the columns headers to disallow the sorting. How can I do that, but without deriving the DataGridView? Is there any other way to disable the sorting of the DataGridView without deriving it?
by: Kyote | last post by:
On my form I have a datagridview that's bound to a table on my DB. When I run the app then click on a column header to sort, it sorts just fine. But my problem is a result of that sort. Even though the view has been sorted, it's underlying data isn't. After sorting I'm trying to get the datarow I just doubleclicked on. The problem is it's returning the pre sorted row. That is, the row that was there before I sorted the column. Dim...
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen. When it is done sorting I want the splash screen dissapear. What I had been doing was using the CellClick and Sorted events: private void myDGV_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) {//sorting
by: Queez | last post by:
OK, this is rediculous... Surely, sorting should be one of the easiest things with the ASP.NET DataGridView control. I mean, there's hundreds of sites out there (Microsoft MSDN entries included) which explain and give examples of the DataGridView sorting and how to make it work... SO WHY CAN'T I GET IT TO WORK?! Dammit! Apologies for the rant. I'll try and keep it to the point from here on in: I have tried the following:
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.