Home Forums WinForms controls Xceed Grid for WinForms Cell border — paintforeground

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17648 |

    I am trying to put a left and right border on all cells in a row. To do this, I have created two classes: MonthlyBorderRow and BorderCell. I got most of the code from the Puzzle sample from Xceed. However, for some reason only the first cell in each row is getting the border. To set the created class as the template, I am using this line: 

     grdMonthly.DataRowTemplate = new MonthlyBorderRow();

     

    I welcome any suggestions or ideas. Please let me know if you need anything else. 

     

    //////////////////////////////////////////////////////////////// 

     public class MonthlyBorderRow : DataRow

        {

            // Default constructor used, in this sample, to create a new data row template

            public MonthlyBorderRow()

                : base()

            {

            }

            // Necessary only if you want to use the ImageRow in the Grid Designer

            public MonthlyBorderRow(RowSelector rowSelector)

                : base(rowSelector)

            {

            }

            // This constructor is use for creating a new ImageRow by cloning the 

            // template passed as a parameter.

            // We must add all the code here to copy the properties of that class.

            // It is called each time the grid needs to create new DataRow objects from the DataRowTemplate

            protected MonthlyBorderRow(MonthlyBorderRow template)

                : base(template)

            {

            }

            // Called when we need to create a cell for this row (When adding a column to the grid for example).

            protected override Cell CreateCell(Column parentColumn)

            {

                return new BorderCell(parentColumn);

            }

            // Creates a clone of a ImageRow object and returns a reference to the

            // newly created row.

            protected override Row CreateInstance()

            {

                return new MonthlyBorderRow(this);

            }

        }

        public class BorderCell : DataCell

        {

            // This constructor is used to creat a new ImageCells by cloning the 

            // template passed as a parameter.

            // We must add all the code here to copy the properties of that class because

            // it is called each time the grid needs to create new DataCell objects from 

            // the existing DataRowTemplate.Cells collection.

            protected BorderCell(BorderCell template)

                : base(template)

            {

            }

            // Initializes a new instance of the DataCell class specifying its parent column. 

            // Used by the ImageRow.CreateCell

            public BorderCell(Column parentColumn)

                : base(parentColumn)

            {

            }

            // Creates a clone of an ImageCell object and returns a reference to the

            // newly created cell

            protected override Cell CreateInstance()

            {

                return new BorderCell(this);

            }

            // Paints the foreground of the cell.

            protected override void PaintForeground(GridPaintEventArgs e)

            {

                Pen pen = new Pen(GridControl.GridLinePen.Color, 2);

                Point point = new Point(e.DisplayRectangle.X + 1, e.DisplayRectangle.Y);

                Point endPoint = new Point(e.DisplayRectangle.X + 1, e.DisplayRectangle.Y + ParentRow.Height – 1);

                e.Graphics.DrawLine(pen, point, endPoint);

                point = new Point(e.DisplayRectangle.X + ParentColumn.Width – 1, e.DisplayRectangle.Y);

                endPoint = new Point(e.DisplayRectangle.X + ParentColumn.Width – 1, e.DisplayRectangle.Y + ParentRow.Height);

                e.Graphics.DrawLine(pen, point, endPoint);

                base.PaintForeground(e);

            }

        } 

    //////////////////////////////////////////////////////////////// 

    Imported from legacy forums. Posted by Aaron (had 1168 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok, I found something new. If the columns are of type Double, the borders are not painted. If I set the columns to type String, the borders paint. Is there any way I can put thick borders on a Double column?

    Imported from legacy forums. Posted by Aaron (had 886 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.