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.v19.1.dll

Syntax

C#: public event RowCellClickEventHandler RowCellClick

VB: event Public RowCellClick As RowCellClickEventHandler

Event Data

The event handler receives an argument of type RowCellClickEventArgs containing data related to this event.

The following RowCellClickEventArgs properties provide information specific to this event.

PropertyDescription
ButtonGets which mouse button was pressed.
CellValueGets the edit value of the clicked cell.
ClicksGets the number of times the mouse button was pressed and released.
ColumnGets the column that contains the clicked cell.
DeltaGets a signed count of the number of detents the mouse wheel has rotated. A detent is one notch of the mouse wheel.
HandledGets or sets a value specifying whether an event has been handled.
HitInfoGets an object that identifies the clicked element.
IsHMouseWheelThis member supports the internal infrastructure, and is not intended to be used directly from your code.
IsMouseEventGets whether these event arguments provide data for the MouseUp, MouseDown, and MouseMove events.
LocationGets the location of the mouse during the generating mouse event.
RowHandleGets the handle of the clicked row.
XGets the x-coordinate of the mouse during the generating mouse event.
YGets the y-coordinate of the mouse during the generating mouse event.        

 

 

 

 

 

 

 

 

 

Remarks

The RowCellClick event does not fire when a user clicks on a row cell if Grid data is editable and the ColumnViewOptionsBehavior.EditorShowMode property is set to MouseDown (or to Default, if multiple row selection is disabled).

The HitInfo parameter is not initialized when this event fires. 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.

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
        }
    }
}

 

转载于:https://www.cnblogs.com/joesphos/p/11225536.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值