Current filter:
                                You should refresh the page.
                                  • Description:
                                    I want to intercept a double click on a grid row or cell and perform a specific action. How to do this?

                                    Answer:
                                    Since GridControl can be in one of two states - editable or non editable, it is necessary to use different approaches for each state.
                                    Let's consider these approaches.

                                    1.  GridControl isn't editable.
                                    In this case, you can handle the GridView.DoubleClickevent and perform your action if the mouse points to a grid row:

                                    [C#]
                                    private void gridView_DoubleClick(object sender, EventArgs e) { DXMouseEventArgs ea = e as DXMouseEventArgs; GridView view = sender as GridView; GridHitInfo info = view.CalcHitInfo(ea.Location); if (info.InRow || info.InRowCell) { string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption(); MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption)); } }
                                    [VB.NET]
                                    Private Sub gridView_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles gridView.DoubleClick Dim ea As DXMouseEventArgs = TryCast(e, DXMouseEventArgs) Dim view As GridView = TryCast(sender, GridView) Dim info As GridHitInfo = view.CalcHitInfo(ea.Location) If info.InRow OrElse info.InRowCell Then Dim colCaption As String = If(info.Column Is Nothing, "N/A", info.Column.GetCaption()) MessageBox.Show(String.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption)) End If End Sub

                                    2. GridControl is editable
                                    In this scenario, when a grid cell is clicked, the cell's in-place editor is shown. As a result, all mouse events are processed by that editor and the GridView.DoubleClickevent doesn't fire.

                                    The simplest way to overcome this behavior is to set the GridView.OptionsBehavior.EditorShowModeproperty to Click. In this case, the GridView.DoubleClickevent will fire before an in-place editor is activated, so your code will be executed as expected.

                                    If this solution isn't suitable for you, you can use another one.
                                    The main idea is to handle the DoubleClick event at the editor level. For this, you can handle the ShownEditorand **HiddenEditor**events in the following manner:

                                    [C#]
                                    BaseEdit editor; private void gridView_ShownEditor(object sender, EventArgs e) { GridView view = sender as GridView; editor = view.ActiveEditor; editor.DoubleClick += editor_DoubleClick; } void gridView_HiddenEditor(object sender, EventArgs e) { editor.DoubleClick -= editor_DoubleClick; editor = null; } void editor_DoubleClick(object sender, EventArgs e) { BaseEdit editor = (BaseEdit)sender; GridControl grid = editor.Parent as GridControl; GridView view = grid.FocusedView as GridView; Point pt = grid.PointToClient(Control.MousePosition); GridHitInfo info = view.CalcHitInfo(pt); if (info.InRow || info.InRowCell) { string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption(); MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption)); } }
                                    [VB.NET]
                                    Private editor As BaseEdit Private Sub gridView_ShownEditor(ByVal sender As Object, ByVal e As EventArgs) Dim view As GridView = TryCast(sender, GridView) editor = view.ActiveEditor AddHandler editor.DoubleClick, AddressOf editor_DoubleClick End Sub Private Sub gridView_HiddenEditor(ByVal sender As Object, ByVal e As EventArgs) RemoveHandler editor.DoubleClick, AddressOf editor_DoubleClick editor = Nothing End Sub Private Sub editor_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Dim editor As BaseEdit = DirectCast(sender, BaseEdit) Dim grid As GridControl = TryCast(editor.Parent, GridControl) Dim view As GridView = TryCast(grid.FocusedView, GridView) Dim pt As Point = grid.PointToClient(Control.MousePosition) Dim info As GridHitInfo = view.CalcHitInfo(pt) If info.InRow OrElse info.InRowCell Then Dim colCaption As String = If(info.Column Is Nothing, "N/A", info.Column.GetCaption()) MessageBox.Show(String.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption)) End If End Sub

                                    Along with this, you may need to allow users to double-click the row indicatorarea, for this, you still need to handle the GridView.DoubleClickevent as it is shown in item #1.

                                    See Also:
                                    How to assign an event handler to the in-place editor
                                    How to Disable the Immediate Opening of In-Place Editors
                                    Why is the DoubleClick event for the GridView not triggered?

                                Show all comments
                                • Mihalis Papadakis 12.29.2012

                                  What if the user clicks on a row and then immediately clicks on the next row?
                                  Following the code provided, the DoubleClick event is still triggered, although the 2 clicks took place on different rows. How to avoid this behavior? Problem is the MouseEventArgs provides info only regarding 2nd click.
                                  Thanks,
                                  Michalis

                                • John (DevExpress Support) 12.29.2012

                                  To resolve this problem you can handle the MouseDown event in the following manner:

                                  [C#]
                                  DateTime mouseDownTime= DateTime.MinValue; GridCell mouseDownCell = new GridCell(GridControl.InvalidRowHandle,null); TimeSpan DoubleClickInterval = new TimeSpan(0,0,0,0,100); private void gridView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { GridHitInfo hi = gridView1.CalcHitInfo(e.Location); if (hi.InRowCell) { if (hi.RowHandle == mouseDownCell.RowHandle && hi.Column == mouseDownCell.Column && mouseDownTime-DateTime.Now < DoubleClickInterval ) DoRowDoubleClick(sender as GridView, e.Location); } mouseDownCell = new GridCell(hi.RowHandle,hi.Column); mouseDownTime = DateTime.Now; } }
                                  [VB.NET]
                                  Private mouseDownTime As DateTime = DateTime.MinValue Private mouseDownCell As New GridCell(GridControl.InvalidRowHandle, Nothing) Private DoubleClickInterval As New TimeSpan(0, 0, 0, 0, 100) Private Sub gridView1_MouseDown(sender As Object, e As MouseEventArgs) If e.Button = System.Windows.Forms.MouseButtons.Left Then Dim hi As GridHitInfo = gridView1.CalcHitInfo(e.Location) If hi.InRowCell Then If hi.RowHandle = mouseDownCell.RowHandle AndAlso hi.Column = mouseDownCell.Column AndAlso mouseDownTime - DateTime.Now < DoubleClickInterval Then DoRowDoubleClick(TryCast(sender, GridView), e.Location) End If End If mouseDownCell = New GridCell(hi.RowHandle, hi.Column) mouseDownTime = DateTime.Now End If End Sub
                                • Jeremiah S. 07.23.2015

                                  Nick, thanks for posting, even if 10 years ago :)
                                  For my solution, I was looking to obtain the value of two particular columns for the row that is double clicked. Your code got me going in the right direction, but instead of using the position of the cursor I found it more effective to use the GridView.GetFocusedRowCellValue( ) method.

                                • Alisher (DevExpress Support) 07.24.2015

                                  Hi Jeremiah,

                                  I am happy to hear that this solution helped you. Feel free to contact us in case of further difficulties.

                                • krishna soni 07.28.2015

                                  hello, I want to select multiple rows in a grid by selecting checkboxes  and perform another operations which i am unable to do it.. please help!!!
                                  Thanks,
                                  krishna

                                • Brendon Muck [DevExpress MVP] 07.31.2015

                                  Please open a new ticket with your question, as it is not related to the original topic.

                                • parisa 09.06.2015

                                  Hi
                                  How can I handle just one time show message box , I mean ,I wana do some other thing after double click but I have some bug in my program that show more than one time message box.

                                • Andrew Ser (DevExpress Support) 09.07.2015

                                  Hello Parisa,
                                  I've extracted your inquiry into a separate thread - Grid - How handle DoubleClick and show MessageBox only once. Let's continue our discussion there.

                                0 Solutions

                                Creation Date Importance Sort by