1、设置 GirdViewt.OptionsBehavior.Editable = false;
设定变量 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = new DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo(); //获取“撞击点”的位置
2、注册GridView的鼠标单击及GridView的双击事件
this.gridView.MouseDown += new MouseEventHandler(gridView_MouseDown); //用于获取GridHitInfo-撞击点的信息
this.gridView.DoubleClick += new EventHandler(gridView_DoubleClick);//双击事件
3、代码
//鼠标单击事件
//获取鼠标点击的位置
void gridView_InpatientPatient_MouseDown(object sender, MouseEventArgs e)
{
hInfo = gridView_InpatientPatient.CalcHitInfo(e.X, e.Y);
}
//界面双击的事件
//双击事件
void gridView_DoubleClick(object sender, EventArgs e)
{
//获取点
if (gridView.FocusedRowHandle < 0) return;
try
{
//双击某一单元格,执行代码
if (hInfo.InRowCell)
{
//获取
int rowid = this.gridView.FocusedRowHandle;
string selectedStr = this.gridView.GetRowCellValue(rowid, "PatientID").ToString();
MessageBox.Show(selectedStr);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}