This is a migrated thread and some comments may be shown as answers.

Persisting row selection

2 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BILLY
Top achievements
Rank 1
BILLY asked on 03 Mar 2012, 08:08 AM
Hi, I would like to be able to persist the row selection after the grid has been refreshed. Here is a brief overview of what I am trying to accomplish. Since RadGridView doesn't support In-Grid row re-ordering using drag and drop when bound, I rolled my own method of reording the rows. My issue now is that when I select a row and reorder it based upon an integer column in the actual datasource, I would like for the row I selected to return to being selected once I refresh the grid with the updated datasource. Everything I have tried has not been successful, but I feel like this is possible. Any ideas out there?

2 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 05 Mar 2012, 01:01 PM
Hi Billy,

It's not the most efficient code, but this did the trick.

Private Sub PopulateAndMaintainRowHighlight()
    Dim selectedItem As String = Me.RadGridView1.Rows(0).Cells("UniqueItem").Value.ToString()
    If Me.RadGridView1.SelectedRows.Count > 0 Then
        selectedItem = Me.RadGridView1.SelectedRows(0).Cells("UniqueItem").Value.ToString()
    End If
 
    Populate() ' re-bind the grid
 
    Me.RadGridView1.CurrentRow = Nothing
 
    For i As Integer = 0 To Me.RadGridView1.ChildRows.Count - 1
        If Me.RadGridView1.ChildRows(i).Cells("UniqueItem").Value.ToString() = selectedItem Then
            Me.RadGridView1.ChildRows(i).IsCurrent = True
            Me.RadGridView1.ChildRows(i).IsSelected = True
            Exit For
        End If
    Next
End Sub
0
Ivan Petrov
Telerik team
answered on 07 Mar 2012, 12:25 PM
Hi guys,

Richard's solution will work in this case, but as he said it is probably not the most efficient one. If you care to share with us the solution you have worked outm we would be in a better position to test and suggest other solutions.

I am looking forward to your reply.

Greetings,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
BILLY
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Ivan Petrov
Telerik team
Share this question
or