private void gv_BlackList_MouseDown(object sender, MouseEventArgs e) { //鼠标左键点击 System.Threading.Thread.Sleep(10); if (e.Button == MouseButtons.Left) { //GridHitInfo gridHitInfo = gridView.CalcHitInfo(e.X, e.Y); DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo gridHitInfo = gv_BlackList.CalcHitInfo(e.X, e.Y); //在列标题栏内且列标题name是"colName" if (gridHitInfo.Column != null) { if (gridHitInfo.InColumnPanel && gridHitInfo.Column.Name == "select") { //获取该列右边线的x坐标 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo gridViewInfo = (DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo) this.gv_BlackList.GetViewInfo(); int x = gridViewInfo.GetColumnLeftCoord(gridHitInfo.Column) + gridHitInfo.Column.Width; //右边线向左移动3个像素位置不弹出对话框(实验证明3个像素是正好的) if (e.X < x - 3) { //XtraMessageBox.Show("点击select列标题!"); for (int i = 0; i < gv_BlackList.RowCount; i++) { //鼠标的那个按钮按下 string dr = gv_BlackList.GetRowCellValue(i, "check").ToString(); if (dr == "1") { gv_BlackList.SetRowCellValue(i, gv_BlackList.Columns["check"], "0"); } else//(dr == "0") { gv_BlackList.SetRowCellValue(i, gv_BlackList.Columns["check"], "1"); } } } } /*else if (!gridHitInfo.InColumnPanel) * { * * int i = gridHitInfo.RowHandle; * string dr = gv_BlackList.GetRowCellValue(i, "check").ToString(); * if (dr == "1") * gv_BlackList.SetRowCellValue(i, gv_BlackList.Columns["check"], "0"); * else//(dr == "0") * gv_BlackList.SetRowCellValue(i, gv_BlackList.Columns["check"], "1"); * * } */ } } }
private bool IsMouseOverButton(int rowHandle, string column, Point point) { bool result = false; DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo vInfo = gvTenders.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo; if (vInfo != null) { DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo cellInfo = vInfo.GetGridCellInfo(rowHandle, gvTenders.Columns[column]); result = cellInfo.Bounds.Contains(point); } return(result); }