KB Article A2629
Visible to All Users

How to assign an event handler to the in-place editor

Description:
The TextEdit control provides the MouseDown event, but the RepositoryItemTextEdit does not. Is it possible to handle the MouseDown or another editor specific event of the grid's in-place editor?

Answer:
When a grid cell is opened for editing, the grid creates an editor instance, which corresponds to the focused grid column's editor repository item. Thus, if the ColumnEdit is a RepositoryItemTextEdit, a TextEdit editor is created and shown. When the in-place editor is displayed, the ShownEditor event is generated and you can attach an event handler to the in-place editor. The editor itself is accessible via the ActiveEditor property.

C#
using DevExpress.XtraEditors; ... BaseEdit activeEditor; private void gridView1_ShownEditor(object sender, System.EventArgs e) { activeEditor = gridView1.ActiveEditor; activeEditor.MouseDown += new MouseEventHandler(Editor_MouseDown); } void Editor_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { ... // your code is here }
Visual Basic
Imports DevExpress.XtraEditors Private Editor As BaseEdit Private Sub GridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.ShownEditor Dim View As GridView = CType(sender, GridView) If View.FocusedColumn.FieldName = "Category" Then Editor = View.ActiveEditor AddHandler Editor.MouseMove, AddressOf InplaceEditor_MouseMove End If End Sub Private Sub InplaceEditor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) ' your code is here End Sub

The event handler must be detached from the in-place editor inside the HiddenEditor event to avoid memory leaks.

C#
private void gridView1_HiddenEditor(object sender, System.EventArgs e) { if(activeEditor != null) { activeEditor.MouseDown -= new MouseEventHandler(Editor_MouseDown); activeEditor = null; } }
Visual Basic
Private Sub GridView1_HiddenEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.HiddenEditor If Not Editor Is Nothing Then RemoveHandler Editor.MouseMove, AddressOf InplaceEditor_MouseMove Editor = Nothing End If End Sub

See Also:
How to handle a double-click on a grid row or cell

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.