)
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 the current cell with various options in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: July 20, 2015 |
Last Revised Date: December 31, 2019

Moving a current cell

By default, the CurrentCell can be moved to a particular cell by using the MoveTo method. This article explains about moving a CurrentCell with the following options:

  • Activating the CurrentCell with cursor at the end position.    

activating the currentcell with cursor at end position

  • Activating the CurrentCell with highlighting the cellvalue.

activating the currentcell with highlighting the cell value

Solution

In order to achieve this, initially the CurrentCell has to be moved to a particular cell by using the MoveTo method. And then the cursor position and cell value highlighting can be achieved by using the CellRenderer or GridTextBoxCellRenderer as follows.

Activating the CurrentCell with cursor at the end position

C#

private void moveBtn_Click(object sender, EventArgs e)
{
     int columnIndex = -1;
     int.TryParse(this.columnIndexText.Text.ToString(), out columnIndex);
     //Getting the record rowIndex based on its position.
     int recordIndex = -1;
     int.TryParse(this.recordIndexText.Text.ToString(), out recordIndex);
     if (recordIndex > 0 && columnIndex > 0)
     {
         //Getting RowIndex and ColumnIndex. 
         columnIndex = this.gridGroupingControl1.TableDescriptor.FieldToColIndex(columnIndex - 1);
         recordIndex = this.gridGroupingControl1.Table.Records[recordIndex - 1].GetRowIndex();
         //Moving the current cell.
         this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(recordIndex, columnIndex, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus);
         this.gridGroupingControl1.Focus();
         //Setting the cursor at end position of cell.
         if (this.gridGroupingControl1.TableControl.CurrentCell.Renderer is GridTextBoxCellRenderer)
            {
                GridTextBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridTextBoxCellRenderer;
                renderer.TextBox.SelectionStart = renderer.TextBox.Text.Length;
            }
      }
}

VB

Private Sub moveBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles moveBtn.Click
       Dim columnIndex As Integer = -1
       Integer.TryParse(Me.columnIndexText.Text.ToString(), columnIndex)
       'Getting the record rowIndex based on its position.
        Dim recordIndex As Integer = -1
        Integer.TryParse(Me.recordIndexText.Text.ToString(), recordIndex)
        If recordIndex > 0 AndAlso columnIndex > 0 Then
          'Getting RowIndex and ColumnIndex. 
           columnIndex = Me.gridGroupingControl1.TableDescriptor.FieldToColIndex(columnIndex - 1)
            recordIndex = Me.gridGroupingControl1.Table.Records(recordIndex - 1).GetRowIndex()
 'Moving the current cell.    Me.gridGroupingControl1.TableControl.CurrentCell.MoveTo(recordIndex, columnIndex, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus)
 Me.gridGroupingControl1.Focus()
 'Setting the cursor at end position of cell.
 If TypeOf Me.gridGroupingControl1.TableControl.CurrentCell.Renderer Is GridTextBoxCellRenderer Then
 Dim renderer As GridTextBoxCellRenderer = TryCast(Me.gridGroupingControl1.TableControl.CurrentCell.Renderer, GridTextBoxCellRenderer)
 renderer.TextBox.SelectionStart = renderer.TextBox.Text.Length
             End If
     End If
End Sub

Screenshot

activating the currentcell with cursor at end position

Figure 1: Activating the CurrentCell with cursor at the end position

Activating the CurrentCell with highlighting the cellvalue

C#

private void moveWithHighlightBtn_Click(object sender, EventArgs e)
{
     int columnIndex = -1;
     int.TryParse(this.columnIndexText.Text.ToString(), out columnIndex);
     //Getting the record rowIndex based on its position.
     int recordIndex = -1;
     int.TryParse(this.recordIndexText.Text.ToString(), out recordIndex);
            if (recordIndex > 0 && columnIndex > 0)
            {
                //Getting RowIndex and ColumnIndex. 
                columnIndex = this.gridGroupingControl1.TableDescriptor.FieldToColIndex(columnIndex - 1);
                recordIndex = this.gridGroupingControl1.Table.Records[recordIndex - 1].GetRowIndex();
                //Moving the current cell.
                this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(recordIndex, columnIndex, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus);
                this.gridGroupingControl1.Focus();
                //Setting the cursor at end position of cell.
                if (this.gridGroupingControl1.TableControl.CurrentCell.Renderer is GridTextBoxCellRenderer)
                {
                    GridTextBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridTextBoxCellRenderer;
                    renderer.TextBox.SelectAll();
                }
           }
}

VB

Private Sub moveWithHighlightBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles moveWithHighlightBtn.Click
       Dim columnIndex As Integer = -1
       Integer.TryParse(Me.columnIndexText.Text.ToString(), columnIndex)
       'Getting the record rowIndex based on its position.
        Dim recordIndex As Integer = -1
        Integer.TryParse(Me.recordIndexText.Text.ToString(), recordIndex)
        If recordIndex > 0 AndAlso columnIndex > 0 Then
          'Getting RowIndex and ColumnIndex. 
           columnIndex = Me.gridGroupingControl1.TableDescriptor.FieldToColIndex(columnIndex - 1)
            recordIndex = Me.gridGroupingControl1.Table.Records(recordIndex - 1).GetRowIndex()
 'Moving the current cell.    Me.gridGroupingControl1.TableControl.CurrentCell.MoveTo(recordIndex, columnIndex, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus)
 Me.gridGroupingControl1.Focus()
 'Setting the cursor at end position of cell.
 If TypeOf Me.gridGroupingControl1.TableControl.CurrentCell.Renderer Is GridTextBoxCellRenderer Then
 Dim renderer As GridTextBoxCellRenderer = TryCast(Me.gridGroupingControl1.TableControl.CurrentCell.Renderer, GridTextBoxCellRenderer)
 renderer.TextBox.SelectAll()
             End If
     End If
End Sub

Screenshot

activating the currentcell with highlighting the cell value

Figure 2: Activating the CurrentCell with highlighting the cellvalue

Samples:

C#: CurrentCell_Moving_CS

VB: CurrentCell_Moving_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