Persisting row selection

3 posts, 0 answers
  1. BILLY
    BILLY avatar
    3 posts
    Member since:
    Dec 2011

    Posted 03 Mar 2012 Link to this post

    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. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 05 Mar 2012 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 07 Mar 2012 Link to this post

    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 >>
Back to Top