Are you sorting the DataSource independent of the grid? (Ie, for example if you external datasource is a DataView, are you sorting things by setting DataView.Sort?). If you sort indendent of the grid, make sure there is not a currently editing cell (by calling grid.CurrentCell.EndEdit) that may be causing a problem when you return from your sort.
Below is a discussion of sorting a virtual grid using the grid itself (and not using the datasource to sort itself).
One option to sort a vistual grid would be to create some sort of index array during your sort where the array tracks in some manner the relationship between the unsorted data and the sorted data. Then in your QueryCellInfo handler, you would use this array to get the proper reference for the requested row.
Attached is a sample in C# that shows an implementation of this idea. Here are some details about the sample.
It uses a two dimensional integer array called VirtData as the datasource for the grid. The datasource has an ArrayList (SortIndexList) with the capacity as the number of rows. It is initially populated with 0,1,2,3.. till the total rowcount. The virtdata class has an indexer that gets and sets the array values using the SortIndexList items. The grid is populated using the QueryCellInfo event handler using this indexer. Since the SortIndexList is populated like 0,1,2,3.. intially, it displays the array vlaues using this indexer.
It uses the "ColumnHeaderCell" to display the up or down sort arrows when the column header cell is clicked to show the sort order. When the header cell is clicked, the SortIndexList''s sort method is called passing in the DataComparer which implements the IComparer interface.
The IComparer re-arranges items (which we loaded intially like 0,1,2,3...) in a way to reflect either the ascending or descending way of array data in that particular column. So when the grid queries for information using the virtdata indexer, it gets the value in a sorted way and displays in the grid.
Sample.