1. 程式人生 > >DevExpress的雙擊獲取單元格資料

DevExpress的雙擊獲取單元格資料

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