Articles in this section

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

TextBox cell events

The embedded WinForms GridControl 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 the following code examples.

// 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");
} 
'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
AddHandler textBoxCellRenderer.TextBox.MouseDown, AddressOf textbox_MouseDown
AddHandler textBoxCellRenderer.TextBox.KeyUp, AddressOf 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

 Screenshots below illustrate the TextBox Cell Events.

 

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: TraceKeyEvnts-VB.zip

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