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 BasicImports 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 BasicPrivate 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