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 capture Mouse and Key events when the text box cell is in an active edit state in WinForms GridControl?

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

TextBox cell events

The embedded text box gets the mouse actions when the text box is active. You can subscribe to the embedded textbox's events that are inside a cell by accessing it by using the cell's renderer. Refer to following code examples.

C#

//In Form_Load()
// Creates a text box cell renderer object.
GridTextBoxCellRenderer textBoxCellRenderer = (GridTextBoxCellRenderer)this.gridControl1.CellRenderers["TextBox"];
//Invokes the MouseDown and KeyUp events of the text box
textBoxCellRenderer.TextBox.MouseDown += new MouseEventHandler(textbox_MouseDown);
textBoxCellRenderer.TextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyUp);           
private void textbox_MouseDown(object sender, MouseEventArgs e)
{
    //Writes the MouseDown action
    Trace.WriteLine("textbox_MouseDown");
}
private void textBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
    //Writes the KeyUp event
    Trace.WriteLine("textBox_KeyUp");
}

 

VB

'In Form_Load()
'Creates a text box cell renderer object.
Private textBoxCellRenderer As GridTextBoxCellRenderer = CType(Me.gridControl1.CellRenderers("TextBox"), GridTextBoxCellRenderer)
'Invokes the MouseDown and KeyUp events of the text box
Private textBoxCellRenderer.TextBox.MouseDown += New MouseEventHandler(AddressOf textbox_MouseDown)
Private textBoxCellRenderer.TextBox.KeyUp += New System.Windows.Forms.KeyEventHandler(AddressOf Me.textBox_KeyUp)
Private Sub textbox_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
     'Writes the MouseDown action
     Trace.WriteLine("textbox_MouseDown")
End Sub
Private Sub textBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
     'Writes the KeyUp event
     Trace.WriteLine("textBox_KeyUp")
End Sub

 

 

Textbox cell event trace in grid control

Figure 1: TextBox cell event trace in grid control.

Trace events list in the text box cell

Figure 2: The traced events list in the text box cell.

 

Samples:

C#: TraceKeyEvents-CS.zip

VB: TraceKeyEvents-VB.zip

 

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