Пример #1
0
        private void bandedGridView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (Control.ModifierKeys != (Keys.Shift | Keys.Control))
            {
                return;
            }
            BandedGridView    view  = (BandedGridView)sender;
            BandedGridHitInfo hInfo = view.CalcHitInfo(e.Location);

            if (hInfo.InColumn)
            {
                view.ClearSelection();
                SelectCells(hInfo.Column);
            }
            else if (hInfo.InBandPanel && hInfo.Band != null)
            {
                view.ClearSelection();
                SelectCells(hInfo.Band);
            }
            else
            {
                return;
            }
            ((DXMouseEventArgs)e).Handled = true;
        }
Пример #2
0
        /// <summary>
        /// 处理表格点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void View_Click(object sender, EventArgs e)
        {
            GridHitInfo info;
            Point       pt = _view.GridControl.PointToClient(Control.MousePosition);

            info = _view.CalcHitInfo(pt);

            if (info.Column == column)
            {
                if (info.InColumn)
                {
                    if (SelectedCount == _view.DataRowCount)
                    {
                        ClearSelection();
                    }
                    else
                    {
                        SelectAll();
                    }
                }

                if (info.InRowCell)
                {
                    InvertRowSelection(info.RowHandle);
                }
            }

            if (info.InRow && _view.IsGroupRow(info.RowHandle) && info.HitTest != GridHitTest.RowGroupButton)
            {
                InvertRowSelection(info.RowHandle);
            }
        }
Пример #3
0
        private void gvwView_DoubleClick(object sender, EventArgs e)
        {
            BandedGridView view = (BandedGridView)sender;

            if (view != null)
            {
                Point             pt   = view.GridControl.PointToClient(Control.MousePosition);
                BandedGridHitInfo info = view.CalcHitInfo(pt);
                DevExpress.XtraGrid.Views.BandedGrid.BandedGridView sndr = sender as DevExpress.XtraGrid.Views.BandedGrid.BandedGridView;
                DevExpress.Utils.DXMouseEventArgs dxMouseEventArgs       = e as DevExpress.Utils.DXMouseEventArgs;
                DevExpress.XtraGrid.Views.BandedGrid.ViewInfo.BandedGridHitInfo hitInfo = sndr.CalcHitInfo(dxMouseEventArgs.Location);
                if (hitInfo.RowHandle < 0)
                {
                    if (hitInfo.Band.Caption.Equals("Chart"))
                    {
                        this.Close();
                        Form fc = Application.OpenForms["FRM_SMT_OS_TOPO_WEEKLY_CHART"];
                        if (fc != null)
                        {
                            fc.Show();
                        }
                        else
                        {
                            FRM_SMT_OS_TOPO_WEEKLY_CHART f = new FRM_SMT_OS_TOPO_WEEKLY_CHART();
                            f.Show();
                        }
                    }
                }
            }
        }
        private void gvwView_DoubleClick(object sender, EventArgs e)
        {
            BandedGridView view = (BandedGridView)sender;

            if (view != null)
            {
                Point             pt   = view.GridControl.PointToClient(Control.MousePosition);
                BandedGridHitInfo info = view.CalcHitInfo(pt);
                DevExpress.XtraGrid.Views.BandedGrid.BandedGridView sndr = sender as DevExpress.XtraGrid.Views.BandedGrid.BandedGridView;
                DevExpress.Utils.DXMouseEventArgs dxMouseEventArgs       = e as DevExpress.Utils.DXMouseEventArgs;
                DevExpress.XtraGrid.Views.BandedGrid.ViewInfo.BandedGridHitInfo hitInfo = sndr.CalcHitInfo(dxMouseEventArgs.Location);
                if (hitInfo.RowHandle < 0)
                {
                    if (hitInfo.Band.Caption.Contains("Chart"))
                    {
                        FRM_SMT_DMP_TOPO_DAILY f1 = new FRM_SMT_DMP_TOPO_DAILY("FORM");
                        f1.Show();
                    }
                }
            }
        }
Пример #5
0
        private void toolTip_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            if (e.SelectedControl == GridGC)
            {
                ToolTipControlInfo info = null;
                //Get the view at the current mouse position
                BandedGridView view = GridGC.GetViewAt(e.ControlMousePosition) as BandedGridView;
                if (view == null)
                {
                    return;
                }
                //Get the view's element information that resides at the current position
                GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
                //Display a hint for row indicator cells
                if (hi.HitTest == GridHitTest.RowIndicator || hi.HitTest == GridHitTest.RowCell && hi.Column.FieldName == "CondenserState")
                {
                    //An object that uniquely identifies a row indicator cell
                    object o    = hi.HitTest.ToString() + hi.RowHandle.ToString();
                    string text = "";

                    DataRow row = GridView.GetDataRow(hi.RowHandle);
                    if (Convert.ToInt64(row["CondenserState"]) == 0)
                    {
                        text = "Работоспособен";
                    }
                    else
                    {
                        text = "Неработоспособен";
                    }

                    info = new ToolTipControlInfo(o, text);
                }
                //Supply tooltip information if applicable, otherwise preserve default tooltip (if any)
                if (info != null)
                {
                    e.Info = info;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// BandedGridView 拖拽
        /// </summary>
        /// <param name="gvMain"></param>
        public static void DragGridRow <T>(this BandedGridView gvMain)
        {
            // 拖拽遮罩控件
            DragMaster dragMaster = new DragMaster();
            // 当前拖拽行绘画区域
            Rectangle _DragRowRect = Rectangle.Empty;

            GridControl gcMain       = gvMain.GridControl;
            GridHitInfo _DownHitInfo = null;

            //表格属性 允许拖拽
            gcMain.AllowDrop = true;
            gvMain.OptionsDetail.EnableMasterViewMode = false;
            #region 将对象拖至边界时发生 DragOver
            gcMain.DragOver += delegate(object sender, System.Windows.Forms.DragEventArgs e)
            {
                if (e.Data.GetDataPresent(typeof(T)))
                {
                    e.Effect = DragDropEffects.Move;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            };
            #endregion

            #region 拖拽完成时处理数据 DragDrop
            gcMain.DragDrop += delegate(object sender, System.Windows.Forms.DragEventArgs e)
            {
                // 拖过来的新数据
                T newRow = (T)e.Data.GetData(typeof(T));
                // 原来在此坐标的数据
                // e的坐标是相对于屏幕的
                var         clientPoint = gcMain.PointToClient(new Point(e.X, e.Y));
                GridHitInfo hitInfo     = gvMain.CalcHitInfo(new Point(clientPoint.X, clientPoint.Y));
                var         oldRow      = (T)gvMain.GetRow(hitInfo.RowHandle);

                // 如果相等则不处理
                if (oldRow == null || newRow == null)
                {
                    return;
                }

                // 且目标位置不是最后一行的话要将所有序号重排
                // 原来的行号
                var oldIndex = _DownHitInfo.RowHandle;
                // 新的行号
                var newIndex = hitInfo.RowHandle;

                BindingSource bs = (BindingSource)(gcMain.DataSource);
                if (bs == null)
                {
                    return;
                }

                bs.RemoveAt(oldIndex);
                bs.Insert(oldIndex, oldRow);
                bs.RemoveAt(newIndex);
                bs.Insert(newIndex, newRow);

                bs.ResetBindings(false);
            };
            #endregion

            #region  标按下 MouseDown
            gcMain.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                _DownHitInfo = null;
                GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(e.X, e.Y));
                if (Control.ModifierKeys != Keys.None)
                {
                    return;
                }
                if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)
                {
                    // 禁用的Grid不支持拖拽
                    if (!gvMain.OptionsBehavior.Editable ||
                        gvMain.OptionsBehavior.ReadOnly)
                    {
                        return;
                    }
                    // 只有点击最前面才能拖拽
                    if (hitInfo.InRowCell)
                    {
                        return;
                    }
                    // 缓存
                    _DownHitInfo = hitInfo;
                }
            };
            #endregion

            #region  标移动 MouseMove
            gcMain.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (_DownHitInfo != null)
                    {
                        Size dragSize = SystemInformation.DragSize;
                        // 偏离区域
                        Rectangle dragRect = new Rectangle(new Point(_DownHitInfo.HitPoint.X - dragSize.Width / 2, _DownHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);

                        if (!dragRect.Contains(new Point(e.X, e.Y)))
                        {
                            // 屏幕坐标
                            var p = gcMain.PointToScreen(e.Location);
                            // 刷新是必须要的
                            gcMain.Refresh();
                            // 获取当前行截图
                            var bmp = GetDragRowImage(gcMain, _DownHitInfo, _DragRowRect);

                            Point offSetPoint = new Point(p.X + 1, p.Y - dragMaster.DragSize.Height / 2);
                            // 开始显示拖拽遮罩
                            dragMaster.StartDrag(bmp, offSetPoint, DragDropEffects.Move);
                            // 获取要拖拽的数据
                            object row = gvMain.GetRow(_DownHitInfo.RowHandle);
                            // 开始拖拽
                            gcMain.DoDragDrop(row, DragDropEffects.Move);
                            // 取消事件
                            DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
                            // 清空缓存
                            _DownHitInfo = null;
                        }
                    }
                }
            };
            #endregion

            #region 在用鼠标拖动某项时发生,是否允许继续拖放 QueryContinueDrag
            gcMain.QueryContinueDrag += delegate(object sender, QueryContinueDragEventArgs e)
            {
                switch (e.Action)
                {
                case DragAction.Continue:
                    // 移动遮罩
                    Point offSetPoint = new Point(Cursor.Position.X + 1, Cursor.Position.Y - dragMaster.DragSize.Height / 2);
                    dragMaster.DoDrag(offSetPoint, DragDropEffects.Move, false);
                    break;

                default:
                    // 清空
                    _DragRowRect = Rectangle.Empty;
                    // 停止拖动
                    dragMaster.EndDrag();
                    break;
                }
            };
            #endregion

            #region 点击行头移动行
            gvMain.CustomDrawRowIndicator += delegate(object sender, RowIndicatorCustomDrawEventArgs e)
            {
                if (_DragRowRect == Rectangle.Empty && _DownHitInfo != null && _DownHitInfo.RowHandle == e.RowHandle)
                {
                    _DragRowRect = e.Bounds;
                }
            };
            #endregion
        }