windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-baseview-e1bff468.md
Occurs when the mouse pointer is over a View and a mouse button is pressed.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Mouse")]
public event MouseEventHandler MouseDown
<DXCategory("Mouse")>
Public Event MouseDown As MouseEventHandler
The MouseDown event's data class is MouseEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Button | Gets which mouse button was pressed. |
| Clicks | Gets the number of times the mouse button was pressed and released. |
| Delta | Gets a signed count of the number of detents the mouse wheel has rotated, multiplied by the WHEEL_DELTA constant. A detent is one notch of the mouse wheel. |
| Location | Gets the location of the mouse during the generating mouse event. |
| X | Gets the x-coordinate of the mouse during the generating mouse event. |
| Y | Gets the y-coordinate of the mouse during the generating mouse event. |
If you handle the MouseDown event for a detail View, the event sender identifies the clone that has actually raised the event.
A common practice of handling the MouseDown event is to perform specific actions in response to pressing a specific View element. Refer to the Hit Information help topic for information on how to identify the element located under the mouse pointer.
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
GridHitInfo info = (sender as GridView).CalcHitInfo(e.Location);
int rowHandle = info.InRow ? info.RowHandle : GridControl.InvalidRowHandle;
MessageBox.Show(rowHandle.ToString());
}
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Private Sub gridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles gridView1.MouseDown
Dim info As GridHitInfo = (TryCast(sender, GridView)).CalcHitInfo(e.Location)
Dim rowHandle As Integer = If(info.InRow, info.RowHandle, GridControl.InvalidRowHandle)
MessageBox.Show(rowHandle.ToString())
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the MouseDown event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-grid-multi-cell-editing/CS/MultiSelectionEditingHelper.cs#L25
this.view.CellValueChanged += view_CellValueChanged;
this.view.MouseDown += view_MouseDown;
}
view.CustomDrawGroupRow += OnCustomDrawGroupRow;
view.MouseDown += OnMouseDown;
view.MouseMove += OnMouseMove;
if(gridListEditor != null && gridListEditor.GridView != null) {
gridListEditor.GridView.MouseDown += GridView_MouseDown;
}
void SubscribeToEvents() {
view.MouseDown += OnViewMouseDown;
view.CustomFilterDisplayText += OnViewCustomFilterDisplayText;
winforms-grid-add-check-box-to-column-header/CS/GridViewColumnHeaderExtender.cs#L255
view.CustomDrawColumnHeader -= OnCustomDrawColumnHeader;
view.MouseDown -= OnMouseDown;
view.MouseUp -= OnMouseUp;
winforms-grid-multi-cell-editing/VB/MultiSelectionEditingHelper.vb#L24
AddHandler Me.view.CellValueChanged, AddressOf view_CellValueChanged
AddHandler Me.view.MouseDown, AddressOf view_MouseDown
End Sub
AddHandler view.CustomDrawGroupRow, AddressOf OnCustomDrawGroupRow
AddHandler view.MouseDown, AddressOf OnMouseDown
AddHandler view.MouseMove, AddressOf OnMouseMove
If gridListEditor IsNot Nothing AndAlso gridListEditor.GridView IsNot Nothing Then
AddHandler gridListEditor.GridView.MouseDown, AddressOf GridView_MouseDown
End If
Private Sub SubscribeToEvents()
AddHandler view.MouseDown, AddressOf OnViewMouseDown
AddHandler view.CustomFilterDisplayText, AddressOf OnViewCustomFilterDisplayText
winforms-grid-add-check-box-to-column-header/VB/GridViewColumnHeaderExtender.vb#L235
RemoveHandler _view.CustomDrawColumnHeader, AddressOf OnCustomDrawColumnHeader
RemoveHandler _view.MouseDown, AddressOf OnMouseDown
RemoveHandler _view.MouseUp, AddressOf OnMouseUp
See Also