How to capture Mouse and Key events when the text box cell is in an active state
9 Dec 2019 / 2 minutes to read
The embedded text box control gets the mouse actions while the text box is active. You can subscribe to the embedded text box’s events inside a cell by accessing it through the cell’s renderer.
private void Form1_Load(object sender, System.EventArgs e)
{
//Creates TextBoxCellRenderer object.
GridTextBoxCellRenderer textBoxCellRenderer = (GridTextBoxCellRenderer) this.grid.CellRenderers["TextBox"];
//Handle Renderer.TextBox.MouseDown to capture mouse events.
textBoxCellRenderer.TextBox.MouseDown += new MouseEventHandler(textbox_MouseDown);
//Handle Renderer.TextBox.KeyUp to capture key events.
textBoxCellRenderer.TextBox.KeyUp += new KeyEventHandler(textBox_KeyUp);
}
private void textbox_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("textbox_MouseDown");
}
private void textBox_KeyUp(object sender, KeyEventArgs e)
{
Console.WriteLine("textBox_KeyUp");
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Creates TextBoxCellRenderer object.
Dim textBoxCellRenderer As GridTextBoxCellRenderer = CType(Me.grid.CellRenderers("TextBox"), GridTextBoxCellRenderer)
'Handle Renderer.TextBox.MouseDown to capture mouse events.
AddHandler textBoxCellRenderer.TextBox.MouseDown, AddressOf textbox_MouseDown
AddHandler textBoxCellRenderer.TextBox.KeyUp, AddressOf textBox_KeyUp
'Form1_Load.
End Sub
Private Sub textbox_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Console.WriteLine("textbox_MouseDown")
End Sub
Private Sub textBox_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Console.WriteLine("textBox_KeyUp")
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