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
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!.
Cheers
Stocki
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
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!.
Cheers
Stocki
Comment