Here is the code to initialize the Double Click Handler for a particular Edit Detail Form:
#region Grid Double Click Handler
private void InitializeDoubleClick() {
UIFramework.GridDoubleClickEventHandler mGDCEH = new GridDoubleClickEventHandler(mDetailGridControl_DoubleClick);
UIFramework.GridDoubleClickHandler mGDCH = new GridDoubleClickHandler(mGDCEH, mDetailGridView);
}
private void mDetailGridView_MouseDown(object sender, MouseEventArgs pMouseEventArgs) {
if (pMouseEventArgs.Button == MouseButtons.Left) {
mMouseHitPoint = new Point(pMouseEventArgs.X, pMouseEventArgs.Y);
}
}
private void mDetailGridControl_DoubleClick(object sender, GridDoubleClickEventArgs e) {
EditDetailEntity();
}
#endregion Grid Double Click Handler
Here is the full text of GridDoublerClickHandler.cs
#region Copyright 2001 - 2005 © IdeaBlade, Inc. All Rights Reserved.
// THIS CODE AND INFORMATION IS SUBJECT TO
// THE IDEABLADE APPLICATION BLOCK END USER AGREEMENT (EULA)
// AND IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMTED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
#endregion Copyright
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
namespace UIFramework {
/// <summary>
/// Handle Double
/// Clicks on GridView Rows.
/// </summary>
/// <remarks>
/// Needed because providing custom action on a row double-click requires using
/// mouse hitinfo to discover the row clicked as implemented here.
/// When the row is known, invoke the client's handler with that row info
/// </remarks>
public class GridDoubleClickHandler {
public GridDoubleClickHandler(GridDoubleClickEventHandler pHandler, GridView pGridView) {
mGridView = pGridView;
mGridView.MouseDown += new MouseEventHandler(GridView_MouseDown);
mGridView.DoubleClick += new EventHandler(GridView_DoubleClick);
this.DoubleClick += pHandler;
}
private void GridView_MouseDown(Object pSender, MouseEventArgs pMouseEventArgs) {
if (pMouseEventArgs.Button == MouseButtons.Left) {
mMouseHitPoint = new Point(pMouseEventArgs.X, pMouseEventArgs.Y);
}
}
private void GridView_DoubleClick(object sender, EventArgs e) {
GridView gv = (GridView) sender;
GridHitInfo hitInfo = gv.CalcHitInfo(mMouseHitPoint);
if (!hitInfo.InRow || gv.IsGroupRow(hitInfo.RowHandle)) return;
OnDoubleClick(gv);
}
public event GridDoubleClickEventHandler DoubleClick;
protected virtual void OnDoubleClick(GridView pGridView) {
if (DoubleClick != null) {
DoubleClick(this, new GridDoubleClickEventArgs(mMouseHitPoint, pGridView));
}
}
~GridDoubleClickHandler() {
if (mGridView != null) {
mGridView.MouseDown -= new MouseEventHandler(GridView_MouseDown);
mGridView.DoubleClick -= new EventHandler(GridView_DoubleClick);
}
mGridView = null;
}
#region MemberVariables
private Point mMouseHitPoint;
private GridView mGridView;
#endregion
}
public delegate void GridDoubleClickEventHandler(object sender, GridDoubleClickEventArgs e);
public class GridDoubleClickEventArgs : System.EventArgs {
public GridDoubleClickEventArgs(Point pMousePoint, GridView pGridView) {
MousePoint = pMousePoint;
GridView = pGridView;
GridHitInfo = GridView.CalcHitInfo(MousePoint);
int aRowHandle = GridHitInfo.RowHandle;
SelectedObject = this.GridView.GetRow(aRowHandle);
if (this.GridView.IsDetailView) {
GridView pv = (GridView) this.GridView.ParentView;
SelectedObjectParent = pv.GetRow(pv.FocusedRowHandle);
}
}
public readonly GridView GridView;
public readonly Point MousePoint;
public readonly GridHitInfo GridHitInfo;
public readonly object SelectedObject = null;
public readonly object SelectedObjectParent = null;
}
}