469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

DatagridView, stop sorting, please

Hi,

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]="" ;
[3,3]=6000

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!.

Cheers

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

And how aer you doing the sort?

Marc
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 ) ; "

Cheers

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

Cheers

Andreas
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.

Regards

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

;-p

http://groups.google.co.uk/group/mic...755c53b05c7a45
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.