We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Re-selecting current row after sorting GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

21991 Nov 30,2004 01:31 PM Dec 1,2004 11:35 AM Windows Forms 2
loading
Tags: GridControl
Tim Aquino
Asked On November 30, 2004 01:31 PM

Hi, Forgive me if this has been asked (and answered) before. I need to highlight/re-select the previously selected row after sorting a GridDataBoundGrid. How do I do this? Thanks, Tim A.

Administrator [Syncfusion]
Replied On November 30, 2004 03:44 PM

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

Tim Aquino
Replied On December 1, 2004 11:35 AM

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
>

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;