Tuesday, February 02, 2010

In my last post I provided a small tutorial on how to use the Client-Side Event API within the ASPxGridView component from DevExpress. In this post I would like to cover another snippet that I came up with that may complement my previous tutorial. This snippet assumes that you have multiple selection enabled in the GridView and wish to preserve the selection as the user pages through results.

If Session("pks") IsNot Nothing Then
Dim selectedPKs As List(Of Object) =
CType(Session("pks"), List(Of Object))
For i As Integer = 0 To selectedPKs.Count - 1
Dim selectedIdx As Integer = ASPxGridView1.

If selectedIdx >= ASPxGridView1.VisibleStartIndex And
selectedIdx <= ASPxGridView1.VisibleStartIndex +
ASPxGridView1.VisibleRowCount Then

ASPxGridView1.FocusedRowIndex = selectedIdx
Exit For
End If
Next i
End If

This snippet goes in the Data_Bound event so that it executes each time the user moves to a different page within the grid view.