Print Page | Close Window

Code for double-click event in DevExpress Grid

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=256
Printed Date: 28-Mar-2024 at 8:02am


Topic: Code for double-click event in DevExpress Grid
Posted By: Customer
Subject: Code for double-click event in DevExpress Grid
Date Posted: 16-Jul-2007 at 10:19am
Could you please send the code sample we spoke of  where double clicking a grid row would launch an edit form for the
record that had been double clicked.
 
An example of what I am referring to appears in the good health demo on the website at approx time marker 4 min 14 sec



Replies:
Posted By: IdeaBlade
Date Posted: 16-Jul-2007 at 10:21am

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;

  }

 

}

 

 


Posted By: thamaluk
Date Posted: 17-Oct-2007 at 3:01pm
Would someone have a working example of this what they would share ?


Posted By: IdeaBlade
Date Posted: 17-Oct-2007 at 4:37pm
This code was taken from an IdeaBlade 2.x application (which would not be of any help to you).


Posted By: roydpnkr
Date Posted: 05-Dec-2008 at 7:00pm
Dim mMouseHitPoint As Point


Private Sub gvResults_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gvResults.MouseDown
        mMouseHitPoint = New Point(e.X, e.Y)
    End Sub

Private Sub gvResults_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvResults.DoubleClick
        Dim info As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo
        info = gvResults.CalcHitInfo(mMouseHitPoint)
        If info.InRow Then
            Dim curRow As Integer = gvResults.FocusedRowHandle
            'Do your work here
        End If
    End Sub


Posted By: liuyupy
Date Posted: 19-Jul-2010 at 12:22am
Thank google. Thank you !



Print Page | Close Window