How to Select all the Contents in a Cell After Double Clicking the Contents in Windows Forms GridDataBoundGrid(Classic)
9 Dec 2019 / 2 minutes to read
CurrentCellControlDoubleClick event can be used to select the contents of a cell by double-clicking it. The current cell is selected by using gridControl1.CurrentCell.Renderer.The length of the content is measured and the contents are selected using Select() method of the inner textbox cell, if it is a textbox cell type.
private void gridControl1_CurrentCellControlDoubleClick(object sender, ControlEventArgs e)
{
GridTextBoxCellRenderer renderer = this.gridControl1.CurrentCell.Renderer as GridTextBoxCellRenderer;
if (renderer.TextBox.TextLength > 0)
{
renderer.TextBox.Select(0, renderer.TextBox.TextLength);
}
}
Private Sub gridControl1_CurrentCellControlDoubleClick(ByVal sender As Object, ByVal e As ControlEventArgs)
Dim renderer As GridTextBoxCellRenderer = TryCast(Me.gridControl1.CurrentCell.Renderer, GridTextBoxCellRenderer)
If renderer.TextBox.TextLength > 0 Then
renderer.TextBox.Select(0, renderer.TextBox.TextLength)
End If
End Sub
If the contents have to be selected using F2 key, CurrentCellKeyDown event can be handled and the contents can be selected.
private void gridControl1_CurrentCellKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
((GridTextBoxCellRenderer)this.gridControl1.CurrentCell.Renderer).TextBox.SelectAll();
}
}
Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.F2 Then
CType(Me.gridControl1.CurrentCell.Renderer, GridTextBoxCellRenderer).TextBox.SelectAll()
End If
End Sub
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page