Completed
Last Updated: 26 Nov 2015 11:54 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Oct 2015 09:08
Category: GridView
Type: Bug Report
0
FIX. RadGridView - duplicated new rows are added when pressing Enter inside a read-only cell
To reproduce:

Sub New()
    InitializeComponent()

    Dim dt As New DataTable()
    dt.Columns.Add("Name", GetType(String))
    dt.Columns.Add("Price", GetType(Decimal))
    dt.Columns.Add("Id", GetType(Integer))
    dt.Columns.Add("ActivatedOn", GetType(DateTime))
    For i As Integer = 0 To 4
        dt.Rows.Add("Item" & i, i * 0.25, i, DateTime.Now.AddHours(i))
    Next
    Me.RadGridView1.DataSource = dt
    Me.RadGridView1.Columns("Id").[ReadOnly] = True
    Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
    AddHandler Me.RadGridView1.DefaultValuesNeeded, AddressOf radGridView1_DefaultValuesNeeded
    Me.RadGridView1.NewRowEnterKeyMode = RadGridViewNewRowEnterKeyMode.EnterMovesToLastAddedRow
End Sub
Private Sub radGridView1_DefaultValuesNeeded(sender As Object, e As GridViewRowEventArgs)
    e.Row.Cells("Id").Value = Me.radGridView1.Rows.Count
    e.Row.Cells("ActivatedOn").Value = DateTime.Now
End Sub

Select the read-only cell inside the new row and press Enter. You will notice that two duplicated rows are added.

Workaround: handle the RadGridView.PreviewKeyDown event and change the current  column to one that is not read-only

 AddHandler Me.RadGridView1.PreviewKeyDown, AddressOf GridPreviewKeyDown

 Private Sub GridPreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs)
        If e.KeyCode = Keys.Enter Then
            Me.RadGridView1.CurrentColumn = Me.RadGridView1.Columns(0)
            Me.RadGridView1.BeginEdit()
        End If
    End Sub 
0 comments