找回密码
 立即注册

QQ登录

只需一步,快速开始

iceman

社区贡献组

270

主题

1万

帖子

1万

积分

社区贡献组

积分
19311

活字格认证微信认证勋章元老葡萄

iceman
社区贡献组   /  发表于:2011-12-19 17:26  /   查看:6431  /  回复:1
这篇文章分享怎样在 Cell 中添加自定义控件。

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

2.具体实现步骤:
    a.创建用户自定义控件 - UserControl,我在这里添加了 FileUpload 和 Calendar 标准控件。
       效果图:
      

png

png

    b.创建自定义单元格类型,代码如下:
  1.         [Serializable]
  2.         public class TestWebControlInCell : FarPoint.Web.Spread.BaseCellType
  3.         {
  4.             public override Control PaintCell(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
  5.             {
  6.                 Control twc;
  7.                 twc = parent.Page.LoadControl("WebUserControl1.ascx");
  8.                 twc.ID = "NewID";
  9.                 return twc;
  10.             }
  11.             public override Control GetEditorControl(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
  12.             {
  13.                 return null;
  14.             }

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

  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             TestWebControlInCell usercontrol = new TestWebControlInCell();
  4.             this.FpSpread1.ActiveSheetView.Cells[0, 0].CellType = usercontrol;
  5.             this.FpSpread1.ActiveSheetView.Columns[0].Width = 300;
  6.             this.FpSpread1.ActiveSheetView.Rows[0].Height = 300;
  7.         }
复制代码
运行查看效果:

png

png

Demo 下载:
编辑环境:VS2010 && Spread for ASP.NET 5.0
usercontrol.zip (1.52 MB, 下载次数: 810)

1 个回复

倒序浏览
chcchb
论坛元老   /  发表于:2013-6-15 11:23:00
沙发
收藏备用.
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部