Articles in this section
Category / Section

How to move the cursor position to the end of the text in WinForms GridGroupingControl?

1 min read

Move the cursor position

To set the record with cursor at end position while moving the cursor dynamically, you can use the CurrentCell.MoveTo method. After moving the CurrentCell to particular cell, you can set the cursor at end position by using CurrentCell.Renderer.

If you want to highlight the cellvalue in cell, you can use renderer.TextBox.SelectAll()method instead of using renderer.TextBox.SelectionStart. 

C#

private void moveBtn_Click(object sender, EventArgs e)
{
    //Set your needed column index
    int colIndex = this.gridGroupingControl1.TableDescriptor.FieldToColIndex(0);
    //Getting the record rowIndex based on its position
    int rowIndex = this.gridGroupingControl1.Table.Records[0].GetRowIndex();
    //Moving the current cell
    this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(rowIndex, colIndex, 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)
     'Set your needed column index
     Dim colIndex As Integer = Me.gridGroupingControl1.TableDescriptor.FieldToColIndex(0)
     'Getting the record rowIndex based on its position
     Dim rowIndex As Integer = Me.gridGroupingControl1.Table.Records(0).GetRowIndex()
     'Moving the current cell
     Me.gridGroupingControl1.TableControl.CurrentCell.MoveTo(rowIndex, colIndex,  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 Sub


Note:

In the below sample, we have provided the two buttons. If you press the “Moving with cursor at end” button, the currentcell will be moved to particular cell with cursor at end position. The currentcell will be moved with highlighting the cellvalue if you press the “Moving with CellValue highlighting” button.

 

 

Screenshot

Show the cursor position in GridGroupingControl

Show the cursor position in GridGroupingControl

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied