Enter edit mode in empty GridView programmatically

3 posts, 1 answers
  1. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 24 Dec 2010 Link to this post

    Hello and merry X-mas to all.
    I have following problem which I cannot solve by my own.
    I have an empty GridView (not bound to any data source).
    I would like to set the Grid in edit mode automatically when the user enters the grid by the tab key.

    So I tried something like this, which does not work.

    Private Sub RadGriedView1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGriedView1.Enter
                Dim currCell As GridViewCellInfo = Me.rgv_Certificates.Rows(0).Cells(1) 'GridCellElement
                currCell.IsSelected = True
    End Sub

    I guess this would work if there are already rows with data. But my grid is empty.
    How can I programmatically activate the edit mode, starting with editing the first cell in the newly added row when the user enters the grid.
    Without using the mouse! Only with tab key.

    Thanks for your help
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 25 Dec 2010 Link to this post

    Hello and Merry Christmas to you too.

    Basically it should work like this, but you don't even need the IsSelected to the cell, you could just check if the Grid.RowCount > 1 and use:
    or, if your grid is empty you could just set the CurrentRow to the

    rgv_Certificates.CurrentRow = rgv_Certificates.MasterView.TableAddNewRow
    and after that call BeginEdit() on that row to put the grid into edit mode.

    Something like this:
    Private Sub radGridView1_Enter(sender As Object, e As EventArgs)
        Dim row = radGridView1.CurrentRow
        If row Is Nothing Then
            row = radGridView1.MasterView.TableAddNewRow
        End If
        If row IsNot Nothing AndAlso row.Cells.Count > 2 Then
        End If
    End Sub

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP

  3. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 26 Dec 2010 Link to this post

    Hello Emanuel,
    thank you so much for your reply. That`s it!
    Cheers Roberto
Back to Top