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

Enter edit mode in empty GridView programmatically

2 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roberto Wenzel
Top achievements
Rank 2
Roberto Wenzel asked on 24 Dec 2010, 07:45 PM
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
            currCell.BeginEdit()
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
Roberto

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 25 Dec 2010, 09:51 PM
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:
Me.rgv_Certificates.Rows(0).Cells(1).BeginEdit()
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
        row.Cells(1).BeginEdit()
    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

0
Roberto Wenzel
Top achievements
Rank 2
answered on 26 Dec 2010, 02:20 PM
Hello Emanuel,
thank you so much for your reply. That`s it!
Cheers Roberto
Tags
GridView
Asked by
Roberto Wenzel
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Roberto Wenzel
Top achievements
Rank 2
Share this question
or