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.
FindVisibleIndexByKeyValue(selectedPKs(i))

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.

3 comments:

Mehul said...

Hi Todd,

Thanks for the snippet, however, the multiple selection should remember the selected rows even between pages. Check out this demo: http://bit.ly/d2pRAL

Todd said...

@mharrydx thanks for the response! I guess I should've been more clear in my description...this snippet will set the focused row to the first selected row it encounters on a page. If this snippet isn't present (and you aren't using checkboxes in your grid) then the focused row defaults to the first row on the page and, in my situation, that caused some confusion for the user.

After seeing the demo I'm going to give the checkbox approach another look.

I'll make an edit to clarify.

Mehul said...

Hi Todd,

Ah, I get you now. You might want to submit a suggestion to the support center as well. Thanks!