DatagridView, stop sorting, please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stocki

    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
    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
  • Marc Gravell

    #2
    Re: DatagridView, stop sorting, please

    What is the datasource of the grid? DataTable/DataView?
    BindingList<T>? non-bound?

    And how aer you doing the sort?

    Marc

    Comment

    • stocki

      #3
      Re: DatagridView, stop sorting, please

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

      Cheers

      Andreas

      Comment

      • stocki

        #4
        Re: DatagridView, stop sorting, please

        .... is there anybody who can give me a hint?

        Cheers

        Andreas

        Comment

        • Marc Gravell

          #5
          Re: DatagridView, stop sorting, please

          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?

          Comment

          • stocki

            #6
            Re: DatagridView, stop sorting, please

            Hi Marc,

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

            Regards

            Andreas

            Comment

            • Marc Gravell

              #7
              Re: DatagridView, stop sorting, please

              Why didn't you just say so?

              ;-p


              Comment

              Working...