Welcome to the Xceed Community | Help
Community Search  
More Search Options

Cell border -- paintforeground

Sort Posts: Previous Next
  •  12-12-2011, 6:02 PM Post no. 31453

    Cell border -- paintforeground

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

            }

        } 


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

  •  12-13-2011, 8:41 AM Post no. 31455 in reply to 31453

    Re: Cell border -- paintforeground

    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?
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.