在 Cell 中添加自定义控件

发布时间:2012/11/14 00:11 发布者:葡萄城产品团队

返回博客中心

这篇文章分享怎样在 Cell 中添加自定义控件。

1.实现方法:
    a.继承 BaseCellType 创建自定单元格类型。
    b.重载 PaintCell 和 GetEditorControl 方法添加自定义控件。

2.具体实现步骤:
    a.创建用户自定义控件 - UserControl,我在这里添加了 FileUpload 和 Calendar 标准控件。
       效果图:
      
    b.创建自定义单元格类型,代码如下:

 
[Serializable]

        public class TestWebControlInCell : FarPoint.Web.Spread.BaseCellType

        {

            public override Control PaintCell(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)

            {

                Control twc;

                twc = parent.Page.LoadControl("WebUserControl1.ascx");

                twc.ID = "NewID";

                return twc;

            }

            public override Control GetEditorControl(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)

            {

                return null;

            }



        }

复制代码

c.应用单元格类型到 Cell 上,代码如下:

 
protected void Page_Load(object sender, EventArgs e)

        {

            TestWebControlInCell usercontrol = new TestWebControlInCell();

            this.FpSpread1.ActiveSheetView.Cells[0, 0].CellType = usercontrol;

            this.FpSpread1.ActiveSheetView.Columns[0].Width = 300;

            this.FpSpread1.ActiveSheetView.Rows[0].Height = 300;

        }

复制代码


Demo 下载:
编辑环境:VS2010 && Spread for ASP.NET 5.0

usercontrol.zip (1.52 M, 下载次数:27)

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网