Completed
Last Updated: 08 Oct 2014 07:15 by ADMIN
ADMIN
Stefan
Created on: 17 Apr 2013 03:10
Category: GridView
Type: Bug Report
2
FIX. RadGridView - EnsureRowVisible does not work when called in the DataBindingComplete event
To reproduce:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        BindGrid()
    End Sub

    Private Sub BindGrid()
        Dim r As New Random()
        Dim table As New DataTable()
        table.Columns.Add("ID", GetType(Integer))
        table.Columns.Add("Name", GetType(String))
        table.Columns.Add("Bool", GetType(Boolean))

        For i As Integer = 0 To 39
            table.Rows.Add(i, "Row " & i, If(r.[Next](10) > 5, True, False))
        Next

        Me.RadGridView1.DataSource = table
    End Sub

    Dim saveName As Integer

    Private Sub RadGridView1_CellEndEdit(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellEndEdit
        If e.Column.Name = "Name" Then
            saveName = RadGridView1.CurrentRow.Cells("ID").Value
            BindGrid()
        End If
    End Sub

    Private Sub RadGridView1_DataBindingComplete(sender As Object, e As Telerik.WinControls.UI.GridViewBindingCompleteEventArgs) Handles RadGridView1.DataBindingComplete
        For Each row As GridViewRowInfo In RadGridView1.Rows
            If row.Cells("ID").Value = saveName Then
                row.IsCurrent = True
                RadGridView1.TableElement.EnsureRowVisible(row)
                Exit For
            End If
        Next
    End Sub
WORKAROUND:
Rebind the grid in the CellValueChanged event instead of the CellEndEdit event:

    Private Sub RadGridView1_CellValueChanged(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellValueChanged
        If e.Column.Name = "Name" Then
            saveName = RadGridView1.CurrentRow.Cells("ID").Value
            BindGrid()
        End If
    End Sub
0 comments