我有一个DevExpress GridControl。我想用它来处理一行双击。我这样做:
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());
}
但是只有点击行指示符或列标题才会收到消息 如何处理对行的单元格的点击?
答案 0 :(得分:5)
基本上你应该处理 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));
}
有关详情,请参阅Devexpress Double Click
注意:此代码仅适用于您的网格不可编辑