Hi,
The solution from the link works fine. The code below (derived GridDataBoundGrid) did not. Anyway, using the solution from the link you''ve provided, the assumption is we have a ''unique'' col (in the example, Col1). What if the datasource does not have a unique col? Is it still possible to re-select the previously selected row after a sort?
Thanks,
Tim A.
>You have to manage this yourself. You can do this by deriving the GridDataBoundGrid and overriding OnSortColumn. The code below assumes there is a PrimaryKey column in the database the the new row position can be easily found after the sort.
>
>Here is a forum link that shows another way of doing this.
>http://64.78.18.34/Support/Forums/message.aspx?MessageID=10655
>
>Here is the derived grid code.
>
>
>Public Class MyGridDataBoundGrid
> Inherits GridDataBoundGrid
> Public Overrides Sub SortColumn(ByVal colIndex As Integer)
> Dim cm As CurrencyManager = Me.Parent.BindingContext(Me.DataSource, Me.DataMember)
> Dim pdc As PropertyDescriptorCollection = cm.GetItemProperties
> Dim pd As PropertyDescriptor = pdc.Find("Col1", True) ’assumes Col1 is primary key column
> Dim val As Object = Me(Me.CurrentCell.RowIndex, 1).Text ’ assumes 1 is the col number of the primary key col, Col1.
> MyBase.SortColumn(colIndex)
> Dim i As Integer = CType(cm.List, IBindingList).Find(pd, val) + 1
> Me.CurrentCell.MoveTo(i, Me.CurrentCell.ColIndex, GridSetCurrentCellOptions.ScrollInView)
> End Sub
>End Class
>