Articles in this section
Category / Section

How to capture Mouse and Key events when the text box cell is in an active edit state in WinForms GridControl?

1 min read

TextBox cell events

The embedded WinForms Grid 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

 

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