Home Forums WinForms controls Xceed Grid for WinForms Sorting of Grid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16699 |

    hi,

    I am sorting the master/detail grid from the column header. I have a column which corresponds to the index of the row.

    for

    (int i = 0; i < m_northWindDataSet.Tables[nIndex].Rows.Count; i++)

    {

    m_northWindDataSet.Tables[nIndex].Rows[ i ].SetField(0, (i + 1).ToString());

    }

    //then I bind this table to grid.

    When I sort a column  in the grid the index column gets jumbled as per the sorting. Now i want that the index column to have values starting from 1 to n or n to 1 even after sorting i.e it resets its values as per sorting. The idea is to get say top 20 values after sorting.

    Imported from legacy forums. Posted by Sudhir (had 1238 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you need this column for the user, or is it only internally in your application that you need it?  If it is only internally, instead of using the an index column, you could use the sorted DataRows list, and retrieve the top 20 rows from it, and do what you need with the rows.

    e.g.: 

    ReadOnlyDataRowList list = gridControl1.GetSortedDataRows( true );

    for( int i = 0; i < 20; i++ )

    {

        Xceed.Grid.

    DataRow row = list[ i ];

        System.Diagnostics.

    Debug.WriteLine( row.Cells[ “SomeColumn” ].Value.ToString() );

    }

     

    If you absolutely need the index column, then I see no other way then to loop through all the rows and change the index column value of each row accordingly.  Again you can use the sorted DataRow list.

    e.g.:

    ReadOnlyDataRowList list = gridControl1.GetSortedDataRows( true );

    for( int i = 0; i < list.Count; i++ )

    {

        list[ i ].Cells[ “IndexColumn” ].Value = ( i + 1 ).ToString();

    }

    Imported from legacy forums. Posted by André (had 915 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.