简体   繁体   中英

How to handle row double click in GridView?

I have a DevExpress GridControl. I want to handle a row doubleclicks with it. I do:

        private void УчасткиGridControlDoubleClick(object sender, EventArgs e)
    {
        GridControl grid = sender as GridControl;
        DXMouseEventArgs args = e as DXMouseEventArgs;
        var hitInfo = grid.Views[0].CalcHitInfo(args.Location) as GridHitInfo;

        MessageBox.Show(hitInfo.HitTest.ToString());
    }

But i get message only if click on Row Indicator or Column Header.
How to handle clicks on row's cells?

Basically you should Handle GridView.DoubleClick

private void УчасткиGridControlDoubleClick(object sender, EventArgs e) {

GridView view = (GridView)sender;

Point pt = view.GridControl.PointToClient(Control.MousePosition);

DoRowDoubleClick(view, pt);

}

   private static void DoRowDoubleClick(GridView view, Point pt) {

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));

}

For more please refer to Devexpress Double Click

Note: This code works only when your grid is not editable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM