Back to Devexpress

GridView.RowCellClick Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-eaf0fa2f.md

latest13.3 KB
Original Source

GridView.RowCellClick Event

Fires when a user clicks a data cell. If data is editable and the ColumnViewOptionsBehavior.EditorShowMode property equals MouseDown (or Default , if multiple row selection is disabled), the event is suppressed.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Action")]
public event RowCellClickEventHandler RowCellClick
vb
<DXCategory("Action")>
Public Event RowCellClick As RowCellClickEventHandler

Event Data

The RowCellClick event's data class is RowCellClickEventArgs. The following properties provide information specific to this event:

PropertyDescription
ButtonGets which mouse button was pressed. Inherited from MouseEventArgs.
CellValueGets the edit value of the clicked cell.
ClicksGets the number of times the mouse button was pressed and released. Inherited from MouseEventArgs.
ColumnGets the column that contains the clicked cell.
DeltaGets 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. Inherited from MouseEventArgs.
HandledGets or sets whether this event should be forwarded to the control’s parent container. Inherited from HandledMouseEventArgs.
HitInfoGets an object that identifies the clicked element. Inherited from RowClickEventArgs.
IsHMouseWheelThis member supports the internal infrastructure, and is not intended to be used directly from your code. Inherited from DXMouseEventArgs.
IsMouseEventGets whether these event arguments provide data for the MouseUp, MouseDown, and MouseMove events. Inherited from DXMouseEventArgs.
LocationGets the location of the mouse during the generating mouse event. Inherited from MouseEventArgs.
RowHandleGets the handle of the clicked row. Inherited from RowClickEventArgs.
XGets the x-coordinate of the mouse during the generating mouse event. Inherited from MouseEventArgs.
YGets the y-coordinate of the mouse during the generating mouse event. Inherited from MouseEventArgs.

The event data class exposes the following methods:

MethodDescription
GetMouseArgs(Control, EventArgs)Converts the MouseEventArgs object passed as a parameter to a DXMouseEventArgs object. Inherited from DXMouseEventArgs.
GetMouseArgs(MouseEventArgs, Boolean)Inherited from DXMouseEventArgs.
GetMouseArgs(MouseEventArgs)Converts the MouseEventArgs object passed as a parameter to a DXMouseEventArgs object. Inherited from DXMouseEventArgs.
Sync()For internal use. Inherited from DXMouseEventArgs.

Remarks

The RowCellClick event does not fire when a user clicks on a row cell if Grid data is editable and one of the following conditions is true:

Note

The HitInfo parameter of the RowCellClick event is not initialized. Use the BaseView.CalcHitInfo method to get a HitInfo object.

Example

In this example, the Data Grid is in non-editable mode (does not invoke cell editors when users click them). Cells under the “State” column cycle through all “ObjectState” enumerator values when a user clicks these cells.

csharp
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

namespace DXApplication3
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            // Add Data Grid
            GridControl gridControl = new GridControl { Parent = this, Dock = DockStyle.Fill };
            GridView gridView = new GridView();
            gridView.OptionsBehavior.Editable = false;
            gridControl.MainView = gridView;
            // Bind to sample data
            List<SomeObject> dataSource = new List<SomeObject>();
            for (int i = 0; i < 4; i++)
                dataSource.Add(new SomeObject { Name = string.Format("Object{0}", i), State = (ObjectState)i });
            gridControl.DataSource = dataSource;

            gridView.RowCellClick += gridView_RowCellClick;
        }

        // When a user clicks any "State" column cell, the cell should change its value
        void gridView_RowCellClick(object sender, RowCellClickEventArgs e) {
            if (e.Column.FieldName == "State") {
                ObjectState state = (ObjectState)e.CellValue;
                ObjectState newState;
                switch (state) {
                    case ObjectState.Normal:
                        newState = ObjectState.Selected;
                        break;
                    case ObjectState.Selected:
                        newState = ObjectState.Highlighted;
                        break;
                    case ObjectState.Highlighted:
                        newState = ObjectState.Hovered;
                        break;
                    default:
                        newState = ObjectState.Normal;
                        break;
                }
                GridView view = sender as GridView;
                view.SetRowCellValue(e.RowHandle, e.Column, newState);
            }
        }

        // Sample data entity
        public class SomeObject {
            public string Name { get; set; }
            public ObjectState State { get; set; }
        }

        // Available values for the "State" column cells
        public enum ObjectState {
            Normal,
            Selected,
            Highlighted,
            Hovered
        }
    }
}
vb
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid

Namespace DXApplication3
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()
            ' Add Data Grid
            Dim gridControl As GridControl = New GridControl With {.Parent = Me, .Dock = DockStyle.Fill}
            Dim gridView As New GridView()
            gridView.OptionsBehavior.Editable = False
            gridControl.MainView = gridView
            ' Bind to sample data
            Dim dataSource As New List(Of SomeObject)()
            For i As Integer = 0 To 3
                dataSource.Add(New SomeObject With {.Name = String.Format("Object{0}", i), .State = CType(i, ObjectState)})
            Next i
            gridControl.DataSource = dataSource

            AddHandler gridView.RowCellClick, AddressOf gridView_RowCellClick
        End Sub

        ' When a user clicks any "State" column cell, the cell should change its value
        Private Sub gridView_RowCellClick(ByVal sender As Object, ByVal e As RowCellClickEventArgs)
            If e.Column.FieldName = "State" Then
                Dim state As ObjectState = CType(e.CellValue, ObjectState)
                Dim newState As ObjectState
                Select Case state
                    Case ObjectState.Normal
                        newState = ObjectState.Selected
                    Case ObjectState.Selected
                        newState = ObjectState.Highlighted
                    Case ObjectState.Highlighted
                        newState = ObjectState.Hovered
                    Case Else
                        newState = ObjectState.Normal
                End Select
                Dim view As GridView = TryCast(sender, GridView)
                view.SetRowCellValue(e.RowHandle, e.Column, newState)
            End If
        End Sub

        ' Sample data entity
        Public Class SomeObject
            Public Property Name() As String
            Public Property State() As ObjectState
        End Class

        ' Available values for the "State" column cells
        Public Enum ObjectState
            Normal
            Selected
            Highlighted
            Hovered
        End Enum
    End Class
End Namespace

See Also

MultiSelect

EditorShowMode

FocusedColumnChanged

FocusedRowChanged

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace