Exemple #1
0
        /// <summary>
        /// Raises the Paint event
        /// </summary>
        /// <param name="e">A PaintCellEventArgs that contains the event data</param>
        protected override void OnPaint(PaintCellEventArgs e)
        {
            base.OnPaint(e);

            // don't bother if the Cell is null
            if (e.Cell == null)
            {
                return;
            }

            Rectangle controlRect = this.CalcControlRect(this.LineAlignment, this.Alignment);

            ControlRendererData controlData = this.GetControlRendererData(e.Cell);

            if (controlData != null && controlData.Control != null)
            {
                controlData.Control.Size     = controlRect.Size;
                controlData.Control.Location = controlRect.Location;
                controlData.Control.BringToFront();

                if (e.Cell.WidthNotSet)
                {
                    e.Cell.ContentWidth = controlRect.Size.Width;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the ControlRendererData specific data used by the Renderer from
        /// the specified Cell
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        protected ControlRendererData GetControlRendererData(Cell cell)
        {
            object rendererData = this.GetRendererData(cell);

            if (this.ControlFactory != null)
            {
                if (rendererData == null || !(rendererData is ControlRendererData))
                {
                    // Never shown a control, so ask what we should do
                    Control control = this.ControlFactory.GetControl(cell);
                    if (control != null)
                    {
                        cell.Row.TableModel.Table.Controls.Add(control);
                        control.BringToFront();

                        ControlRendererData data = new ControlRendererData(control);
                        this.SetRendererData(cell, data);
                        rendererData = data;
                    }
                }
                else
                {
                    // Already got a control, but should we swap it for another
                    ControlRendererData data       = (ControlRendererData)rendererData;
                    Control             oldControl = data.Control;
                    // This next call allows the properties of the control to be updated, or to provide
                    // an entirely new control
                    Control newControl = this.ControlFactory.UpdateControl(cell, data.Control);
                    if (newControl != null)
                    {
                        // We need to take off the old control and wire up the new one
                        cell.Row.TableModel.Table.Controls.Remove(oldControl);
                        cell.Row.TableModel.Table.Controls.Add(newControl);
                        data.Control = newControl;
                        newControl.BringToFront();
                    }
                }
            }

            return((ControlRendererData)rendererData);
        }