New Posts New Posts RSS Feed: Code for double-click event in DevExpress Grid
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Forum LockedCode for double-click event in DevExpress Grid

 Post Reply Post Reply
Author
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Topic: Code for double-click event in DevExpress Grid
    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
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post 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;

  }

 

}

 

 
Back to Top
thamaluk View Drop Down
Newbie
Newbie
Avatar

Joined: 12-Oct-2007
Posts: 10
Post Options Post Options   Quote thamaluk Quote  Post ReplyReply Direct Link To This Post Posted: 17-Oct-2007 at 3:01pm
Would someone have a working example of this what they would share ?
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post 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).
Back to Top
roydpnkr View Drop Down
Newbie
Newbie


Joined: 05-Dec-2008
Posts: 1
Post Options Post Options   Quote roydpnkr Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
liuyupy View Drop Down
Newbie
Newbie


Joined: 19-Jul-2010
Posts: 1
Post Options Post Options   Quote liuyupy Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jul-2010 at 12:22am
Thank google. Thank you !
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down