)
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 select all the text on clicking the cell in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 18, 2019
Tags: selection

Selection

In GridControl, the current cells behavior is controlled by the grid’s ActivateCurrentCellBehavior property. When the property is set to SelectAll, it selects all the text in the cell when the cell becomes the current cell.

C#

//set to select all the text in the current cell
this.gridControl1.ActivateCurrentCellBehavior = Syncfusion.Windows.Forms.Grid.GridCellActivateAction.SelectAll;

 

VB

'set to select all the text in the current cell
Me.gridControl1.ActivateCurrentCellBehavior = Syncfusion.Windows.Forms.Grid.GridCellActivateAction.SelectAll

After applying the properties, the grid is shown as follows,

Select the text in the cell

Figure 1: Selects all the text in the cell

Samples:

C#: SelectAll Text

VB: SelectAll Text

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Adam Bruss
Aug 17, 2016
How can I select all the text in a cell when the user is editing a cell and presses Ctrl+A? Reply
Neelakandan Kannan [Syncfusion]
Aug 19, 2016

Hi Adam,

 

Thanks for using Syncfusion products.

 

 

 

Query

Select all the text in a cell when the user is editing a cell and presses Ctrl+A

 

 

Solution - 1

The reported scenario can be achieved by setting the CellType as OriginalTextBox. Please make use of below code,

 

Code snippet

this.gridControl1.TableStyle.CellType = GridCellTypeName.OriginalTextBox;

 

 

 

Solution – 2

You can also handle the CurrentCellKeyDown event to achieve the reported scenario. Please make use of below code,

 

Code snippet

 

this.gridControl1.CurrentCellKeyPress += new KeyPressEventHandler(gridControl1_CurrentCellKeyPress);

 

 

void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)

{

    if (((Control.ModifierKeys & Keys.Control) != Keys.None) && char.IsLetter('A'))

    {

        if (this.gridControl1.CurrentCell.IsEditing)

        {

            GridTextBoxCellRenderer renderer = this.gridControl1.CurrentCell.Renderer as GridTextBoxCellRenderer;

            renderer.TextBox.SelectAll();

        }

    }

}

 

 

 

Regards,

Neelakandan

Reply

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