)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to move a current cell focus to the first cell of the add new row in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: June 8, 2017 |
Last Revised Date: December 23, 2019
Tags: addnewrow, focus

Adding new record

By default, the focus will be set to the newly added row when the record is added by using AddNewRecordRow. In order to set focus to the AddNewRecordRow after a new record is added, SourceListRecordChanged and TableControlCurrentCellKeyDown events can be used. In SourceListRecordChanged event, LastChangedRecord property can be used to avoid the focus moving to newly added row and TableControlCurrentCellKeyDown event, SetCurrent() method can be used to set the first column as CurrentCell.

C#

//Event Triggering to avoid last focus if new record is added
this.gridGroupingControl1.SourceListRecordChanged += GridGroupingControl_SourceListRecordChanged;
 
//Event customization
 private void GridGroupingControl_SourceListRecordChanged(object sender,RecordChangedEventArgs e)
 {
     if (e.Action == RecordChangedType.Added)
     {
         //To avoid the last focus
         this.gridGroupingControl1.Table.LastChangedRecord = null;
     }
 }
 
//Event Triggering to set cursor on current cell
this.gridGroupingControl1.TableControlCurrentCellKeyDown += GridGroupingControl_TableControlCurrentCellKeyDown;
 
//Event Customization
private void GridGroupingControl_TableControlCurrentCellKeyDown(object sender,GridTableControlKeyEventArgs e)
{
    {
        if (e.Inner.KeyCode == Keys.Enter &&
            this.gridGroupingControl1.Table.CurrentRecord is AddNewRecord)
        {
            //To set focus for first cell of AddNewRecordRow provide first column name 
            this.gridGroupingControl1.Table.AddNewRecord.SetCurrent("Column_Name");
        }
    }
}

 

VB

'Event Triggering to avoid last focus if new record is added
AddHandler Me.gridGroupingControl1.SourceListRecordChanged, AddressOf GridGroupingControl_SourceListRecordChanged
 
'Event customization
Private Sub GridGroupingControl_SourceListRecordChanged(ByVal sender As Object, ByVal e As RecordChangedEventArgs)
    If e.Action = RecordChangedType.Added Then
        'To avoid the last focus
        Me.gridGroupingControl1.Table.LastChangedRecord = Nothing
    End If
End Sub
 
'Event Triggering to set cursor on current cell
AddHandler Me.gridGroupingControl1.TableControlCurrentCellKeyDown, AddressOf GridGroupingControl_TableControlCurrentCellKeyDown
 
'Event Customization
Private Sub GridGroupingControl_TableControlCurrentCellKeyDown(ByVal sender As Object, ByVal e As GridTableControlKeyEventArgs)
        If e.Inner.KeyCode = Keys.Enter AndAlso TypeOf Me.gridGroupingControl1.Table.CurrentRecord Is AddNewRecord Then
            'To set focus for first cell of AddNewRecordRow provide first column name 
            Me.gridGroupingControl1.Table.AddNewRecord.SetCurrent("Column_Name")
        End If
End Sub

 

Screenshot

Adding new record into GridGroupingControl

Samples:

C#: AddNewRecordRow_Focus_CS

VB: AddNewRecordRow_Focus_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon