public override Size GetDragHintSize(ISupportDrop dropTarget)
        {
            int width  = 1;
            int height = 1;

            if (this.DragHint.Image != null)
            {
                width  = this.DragHint.Image.Size.Width;
                height = this.DragHint.Image.Size.Height;
            }
            GridHeaderCellElement headerCellElement = dropTarget as GridHeaderCellElement;

            if (headerCellElement != null)
            {
                if (this.orientation == Orientation.Vertical)
                {
                    height = headerCellElement.Size.Height + this.DragHint.Margins.Vertical;
                }
                else
                {
                    width = headerCellElement.Size.Width + this.DragHint.Margins.Horizontal;
                }
            }
            return(new Size(width, height));
        }
        public override Point GetDragHintLocation(ISupportDrop dropTarget, Point mousePosition)
        {
            GridHeaderCellElement headerCellElement  = dropTarget as GridHeaderCellElement;
            Rectangle             boundingRectangle1 = headerCellElement.ControlBoundingRectangle;
            Rectangle             boundingRectangle2 = headerCellElement.RowElement.TableElement.ViewElement.ControlBoundingRectangle;

            if (boundingRectangle1.Right > boundingRectangle2.Right)
            {
                boundingRectangle1.Width -= boundingRectangle1.Right - boundingRectangle2.Right;
            }
            if (boundingRectangle1.X < boundingRectangle2.X)
            {
                boundingRectangle1.Width -= boundingRectangle2.X - boundingRectangle1.X;
                boundingRectangle1.X      = boundingRectangle2.X;
            }
            Rectangle screen = this.GridViewElement.ElementTree.Control.RectangleToScreen(boundingRectangle1);
            Size      size   = Size.Empty;

            if (this.DragHint.Image != null)
            {
                size = this.DragHint.Image.Size;
            }
            Padding margins      = this.DragHint.Margins;
            Point   dropLocation = headerCellElement.PointFromScreen(mousePosition);

            if (this.orientation == Orientation.Vertical)
            {
                return(new Point((RadGridViewDragDropService.IsDroppedAtLeft(dropLocation, headerCellElement.Size.Width) ? screen.X : screen.Right) - size.Width / 2, screen.Y - margins.Top));
            }
            return(new Point(screen.X - margins.Left, screen.Bottom - margins.Top - size.Height / 2));
        }
Ejemplo n.º 3
0
        private void dgv_01_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
        {
            GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;

            if (cell != null)
            {
                cell.Font = new Font(new FontFamily("Segoe UI"), 11f);
            }
        }
Ejemplo n.º 4
0
        private void MasterTemplate_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;

            if (cell != null)
            {
                cell.Font = new Font(new FontFamily("Segoe UI"), 11f);
            }
        }
Ejemplo n.º 5
0
            protected override void OnMouseUp(MouseEventArgs e)
            {
                base.OnMouseUp(e);

                this.Capture = false;
                this.moving  = false;

                GridTableHeaderRowElement headerRowElement = this.owner.GetRowElement(this.owner.ViewInfo.TableHeaderRow) as GridTableHeaderRowElement;

                if (headerRowElement != null)
                {
                    Point point = new Point(e.X, headerRowElement.ControlBoundingRectangle.Y + headerRowElement.ControlBoundingRectangle.Height / 2);
                    GridHeaderCellElement cellElement = this.ElementTree.GetElementAtPoint <GridHeaderCellElement>(point);

                    if (cellElement != null)
                    {
                        int half = 0;

                        if (e.X > cellElement.ControlBoundingRectangle.X + cellElement.ControlBoundingRectangle.Width / 2)
                        {
                            half++;
                        }

                        while (this.owner.ViewTemplate.PinnedColumns.Count > 0)
                        {
                            this.owner.ViewTemplate.PinnedColumns[0].IsPinned = false;
                        }

                        for (int i = 0; i < cellElement.ColumnIndex + half; i++)
                        {
                            this.owner.ViewTemplate.Columns[i].IsPinned = true;
                        }
                    }
                    else
                    {
                        if (e.X < this.owner.RowHeaderColumnWidth)
                        {
                            while (this.owner.ViewTemplate.PinnedColumns.Count > 0)
                            {
                                this.owner.ViewTemplate.PinnedColumns[0].IsPinned = false;
                            }
                        }
                        else if (e.X > this.owner.ControlBoundingRectangle.Right - this.owner.VScrollBar.Size.Width)
                        {
                            foreach (GridViewColumn col in this.owner.ViewTemplate.Columns)
                            {
                                col.IsPinned = true;
                            }
                        }
                    }
                }

                this.PositionOffset = SizeF.Empty;
                this.owner.InvalidateMeasure();
                this.owner.UpdateLayout();
            }
Ejemplo n.º 6
0
        public override bool OnMouseDown(MouseEventArgs e)
        {
            this.disableSortOrderChange = false;
            bool flag = true;

            if (this.GridViewElement.IsInEditMode)
            {
                flag = this.GridViewElement.EndEdit();
            }
            if (e.Button == MouseButtons.Left)
            {
                this.FindCellToResize(e.Location);
                if (this.columnToResize != null)
                {
                    this.mouseIsDown         = true;
                    this.mouseDownPoint      = e.Location;
                    this.GridControl.Capture = true;
                    this.RootGridBehavior.LockBehavior((IGridBehavior)this);
                    this.cellToResize  = this.GridViewElement.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
                    this.mouseDownCell = this.cellToResize;
                }
                else
                {
                    if (!flag)
                    {
                        return(true);
                    }
                    GridHeaderCellElement cellAtPoint = this.RootGridBehavior.CellAtPoint as GridHeaderCellElement;
                    if (GridVisualElement.GetElementAtPoint <RadButtonElement>((RadElementTree)this.GridViewElement.ElementTree, e.Location) != null)
                    {
                        return(false);
                    }
                    this.mouseDownCell = (GridCellElement)cellAtPoint;
                    if (cellAtPoint == null || this.GetVisibleColumnsCount(cellAtPoint) < 2)
                    {
                        return(false);
                    }
                    RadDragDropService service = this.GridViewElement.GetService <RadDragDropService>();
                    if (service != null)
                    {
                        service.Start((object)new SnapshotDragItem((RadItem)cellAtPoint));
                        service.Stopped     += new EventHandler(this.dragDropService_Stopped);
                        this.dragDropStarted = service.State == RadServiceState.Working;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                this.RootGridBehavior.CellAtPoint?.ShowContextMenu();
            }
            return(false);
        }
Ejemplo n.º 7
0
        private void StyleSelectedCell(GridHeaderCellElement cell)
        {
            bool selected = false;
            bool current  = false;

            foreach (GridViewCellInfo selectedCell in this.gridView.SelectedCells)
            {
                if (cell.ColumnInfo.Index == selectedCell.ColumnInfo.Index)
                {
                    if (cell.ColumnInfo == this.gridView.CurrentColumn)
                    {
                        current = true;
                    }
                    else
                    {
                        selected = true;
                    }
                    break;
                }
            }
            if (current)
            {
                cell.DrawFill         = true;
                cell.NumberOfColors   = 2;
                cell.BackColor        = Color.FromArgb(255, 226, 160);
                cell.BackColor2       = Color.FromArgb(255, 205, 102);
                cell.BorderColor      = Color.FromArgb(255, 190, 106);
                cell.BorderInnerColor = Color.FromArgb(255, 245, 162);
            }
            else if (selected)
            {
                cell.DrawFill         = true;
                cell.NumberOfColors   = 1;
                cell.BackColor        = Color.FromArgb(255, 231, 174);
                cell.BorderColor      = Color.FromArgb(209, 225, 245);
                cell.BorderInnerColor = Color.White;
            }
            else
            {
                cell.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
                cell.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                cell.ResetValue(LightVisualElement.BackColor2Property, ValueResetFlags.Local);
                cell.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                cell.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
                cell.ResetValue(LightVisualElement.BorderInnerColorProperty, ValueResetFlags.Local);
            }
        }
Ejemplo n.º 8
0
        private int GetVisibleColumnsCount(GridHeaderCellElement cell)
        {
            if (cell == null || cell.TableElement == null)
            {
                return(0);
            }
            IList <GridViewColumn> renderColumns = cell.TableElement.ViewElement.RowLayout.RenderColumns;
            int num = 0;

            foreach (GridViewColumn gridViewColumn in (IEnumerable <GridViewColumn>)renderColumns)
            {
                if (gridViewColumn is GridViewDataColumn)
                {
                    ++num;
                }
            }
            return(num);
        }
        public override void UpdateDropContext(
            ISupportDrag draggedContext,
            ISupportDrop dropTarget,
            Point?location)
        {
            GridColumnGroupCellElement groupCellElement    = dropTarget as GridColumnGroupCellElement;
            GridHeaderCellElement      headerCellElement   = dropTarget as GridHeaderCellElement;
            GridViewGroupColumn        gridViewGroupColumn = groupCellElement != null ? groupCellElement.ColumnInfo as GridViewGroupColumn : (GridViewGroupColumn)null;

            if (headerCellElement == null || !location.HasValue)
            {
                this.orientation = Orientation.Vertical;
            }
            else
            {
                if (headerCellElement.RowElement == null || headerCellElement.RowElement.TableElement == null)
                {
                    return;
                }
                Rectangle boundingRectangle1 = headerCellElement.ControlBoundingRectangle;
                Rectangle boundingRectangle2 = headerCellElement.RowElement.TableElement.ViewElement.ControlBoundingRectangle;
                if (boundingRectangle1.Right > boundingRectangle2.Right)
                {
                    boundingRectangle1.Width -= boundingRectangle1.Right - boundingRectangle2.Right;
                }
                if (boundingRectangle1.X < boundingRectangle2.X)
                {
                    boundingRectangle1.Width -= boundingRectangle2.X - boundingRectangle1.X;
                    boundingRectangle1.X      = boundingRectangle2.X;
                }
                if ((RadGridViewDragDropService.GetDropPosition(headerCellElement.PointFromScreen(location.Value), headerCellElement.Size) & RadPosition.Bottom) != RadPosition.None && (gridViewGroupColumn != null && gridViewGroupColumn.Group.Rows.Count == 0 && draggedContext.GetDataContext() is GridViewGroupColumn || gridViewGroupColumn != null && gridViewGroupColumn.Group.Groups.Count == 0 && draggedContext.GetDataContext() is GridViewDataColumn || gridViewGroupColumn == null))
                {
                    this.orientation = Orientation.Horizontal;
                }
                else
                {
                    this.orientation = Orientation.Vertical;
                }
            }
        }
Ejemplo n.º 10
0
        private bool FindCellToResize(Point pt)
        {
            GridTableHeaderRowElement rowAtPoint = this.RootGridBehavior.RowAtPoint as GridTableHeaderRowElement;

            if (rowAtPoint == null || pt.X > rowAtPoint.ControlBoundingRectangle.Right)
            {
                return(false);
            }
            for (int index = 0; index < rowAtPoint.VisualCells.Count; ++index)
            {
                GridCellElement       visualCell        = rowAtPoint.VisualCells[index];
                GridHeaderCellElement headerCellElement = visualCell as GridHeaderCellElement;
                if (headerCellElement != null && headerCellElement.ColumnInfo != null && (headerCellElement.ColumnInfo.AllowResize && headerCellElement.ColumnInfo.OwnerTemplate.AllowColumnResize))
                {
                    if (headerCellElement.ColumnInfo.MaxWidth == 0 || headerCellElement.ColumnInfo.MaxWidth != headerCellElement.ColumnInfo.MinWidth)
                    {
                        int             delta1         = 0;
                        int             delta2         = 0;
                        bool            flag           = this.IsMouseInCellBounds(pt, visualCell, out delta1);
                        GridCellElement elementAtPoint = headerCellElement.ElementTree.GetElementAtPoint(pt) as GridCellElement;
                        if (flag && elementAtPoint != null && (this.IsMouseInCellBounds(pt, elementAtPoint, out delta2) && delta2 < delta1))
                        {
                            this.SetResizeCursor(elementAtPoint.ColumnInfo);
                            this.rowLayout = rowAtPoint.TableElement.ViewElement.RowLayout;
                            return(true);
                        }
                        if (flag)
                        {
                            this.SetResizeCursor(headerCellElement.ColumnInfo);
                            this.rowLayout = rowAtPoint.TableElement.ViewElement.RowLayout;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 11
0
        private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;

            if (cell != null)
            {
                cell.Font      = pop;
                cell.ForeColor = Color.Black;
                cell.BackColor = Color.AliceBlue;
            }

            if (e.CellElement.Text == "0")
            {
                e.CellElement.Text          = "NG";
                e.CellElement.BackColor     = Color.Red;
                e.CellElement.TextAlignment = ContentAlignment.MiddleCenter;
            }

            if (e.CellElement.Text == "1")
            {
                e.CellElement.Text          = "OK";
                e.CellElement.BackColor     = Color.LimeGreen;
                e.CellElement.TextAlignment = ContentAlignment.MiddleCenter;
            }

            if (e.CellElement.Text == "2")
            {
                e.CellElement.Text          = "OFF"; e.CellElement.BackColor = Color.Gray;
                e.CellElement.TextAlignment = ContentAlignment.MiddleCenter;
            }

            if (e.CellElement.Text == "3")
            {
                e.CellElement.Text = "WAIT";
            }
        }
Ejemplo n.º 12
0
        public override bool OnMouseUp(MouseEventArgs e)
        {
            GridCellElement mouseDownCell = this.mouseDownCell;

            this.mouseDownCell = (GridCellElement)null;
            if (this.cellToResize != null)
            {
                int num = (int)this.cellToResize.SetValue(RadElement.IsMouseDownProperty, (object)false);
                this.cellToResize = (GridCellElement)null;
            }
            if (this.columnToResize != null && this.rowLayout != null)
            {
                this.rowLayout.EndColumnResize();
                if (this.GridViewElement.AutoSizeRows && this.columnToResize.WrapText)
                {
                    RadElement radElement = this.GridViewElement.ElementTree.GetElementAtPoint(e.Location);
                    while (radElement != null && !(radElement is GridTableElement))
                    {
                        radElement = radElement.Parent;
                    }
                }
                this.RootGridBehavior.UnlockBehavior((IGridBehavior)this);
                this.mouseIsDown         = false;
                this.GridControl.Capture = false;
                this.columnResizeStarted = false;
                this.rowLayout           = (IGridRowLayout)null;
                this.columnToResize      = (GridViewColumn)null;
                this.ResetCursor();
                return(false);
            }
            if (this.dragDropStarted)
            {
                RadService service = (RadService)this.GridViewElement.GetService <RadDragDropService>();
                this.dragDropStarted = false;
                if (service != null && (service.State == RadServiceState.Working || service.State == RadServiceState.Initial))
                {
                    return(true);
                }
            }
            else
            {
                GridHeaderCellElement cellAtPoint = this.RootGridBehavior.CellAtPoint as GridHeaderCellElement;
                if (cellAtPoint == null || (e.Location.X < cellAtPoint.ControlBoundingRectangle.X + 3 || this.disableSortOrderChange))
                {
                    return(false);
                }
                if (this.MasterTemplate.CurrentRow is GridViewNewRowInfo && this.GridViewElement.ContextMenuManager.ContextMenu == null)
                {
                    this.MasterTemplate.CurrentRow = (GridViewRowInfo)null;
                }
                if (e.Button == MouseButtons.Left)
                {
                    if (cellAtPoint != null && cellAtPoint == mouseDownCell)
                    {
                        RadSortOrder sortOrder;
                        switch (cellAtPoint.SortOrder)
                        {
                        case RadSortOrder.Ascending:
                            sortOrder = RadSortOrder.Descending;
                            break;

                        case RadSortOrder.None:
                            sortOrder = RadSortOrder.Ascending;
                            break;

                        default:
                            GridViewDataColumn columnInfo = cellAtPoint.ColumnInfo as GridViewDataColumn;
                            sortOrder = columnInfo == null || columnInfo.AllowNaturalSort ? RadSortOrder.None : RadSortOrder.Ascending;
                            break;
                        }
                        cellAtPoint.Sort(sortOrder);
                    }
                    return(false);
                }
            }
            return(base.OnMouseUp(e));
        }