471,853 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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
DataGridViewColumnSortMode.Programmatic for each column, I do the
sorting within the "dgrdDetails_ColumnHeaderMouseClick" Event. Steps
are as follows:

- Deleting the row with the sum, which is row 3
- Initiating the sort by:
this.dgrdDetails.Sort( this.dgrdDetails.Columns[e.ColumnIndex],
ListSortDirection.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.dgrdDetails.Sort" and
before adding the row with the sum:

for ( int g = 0; g <= this.dgrdDetails.Columns.Count - 1 ; g ++ )
this.dgrdDetails.Columns[g].SortMode =
DataGridViewColumnSortMode.NotSortable ;

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

How can I stop the DataGridView from sorting?

Any hint is highly appreciated!.


Apr 7 '08 #1
6 4623
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.dgrdDetails.Sort( this.dgrdDetails.Columns[e.ColumnIndex],
ListSortDirection.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Chris Botha | last post: by
7 posts views Thread by Rainer Queck | last post: by
reply views Thread by mahesh.nimbalkar | last post: by
1 post views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
8 posts views Thread by Kyote | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by aboka | last post: by

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.