找回密码
 立即注册

QQ登录

只需一步,快速开始

xxwood

初级会员

35

主题

81

帖子

240

积分

初级会员

积分
240

活字格认证

xxwood
初级会员   /  发表于:2012-2-13 17:15  /   查看:8609  /  回复:8
我想要指定一列的单元格为下拉框,我在设计器里选中那个单元格指定了CellType,但是显示后只有第一行变成了下拉框,后面的行都不是。我想在设计器里指定那一列的CellType,但是却不让(选什么都自动变成none)。到底该怎么办呢?还有如何让下拉框的内容从数据库读取而不是事先填好的?

另外,帮助里为什么都是用代码来实现啊,能不能点点鼠标就实现了的啊?纠结。。。

8 个回复

倒序浏览
J2.NETe
新手上路   /  发表于:2012-2-13 18:44:00
沙发
选中列头,并且确认右边property grid,的下拉菜单上显示的是column。
Really?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-2-13 18:52:00
板凳

回复 1# xxwood 的帖子

xxwood 你好:
1.问题一:我使用 Spread Designer 设定第一列单元格类型,需要先选择列头,然后添加单元格类型。
2.问题二:需要使用代码实现,请使用以下代码测试:


  1.             FpSpread1 = new FarPoint.Web.Spread.FpSpread();
  2.             FpSpread1.ID = "FpSpread1";
  3.             FpSpread1.Style["Position"] = "Absolute";
  4.             FpSpread1.Height = 400;
  5.             FpSpread1.Width = 800;
  6.             FpSpread1.Style["Top"] = "25px";
  7.             FpSpread1.Style["Left"] = "100px";
  8.             FarPoint.Web.Spread.SheetView sv = new FarPoint.Web.Spread.SheetView();
  9.             FpSpread1.Sheets.Add(sv);
  10.             form1.Controls.Add(FpSpread1);

  11.             DataSet ds = new System.Data.DataSet();
  12.             DataTable name;
  13.             DataTable city;
  14.             name = ds.Tables.Add("Customers");
  15.             name.Columns.AddRange(new DataColumn[] {new DataColumn("LastName", typeof(string)), new DataColumn("FirstName", typeof(string)),
  16. new DataColumn("ID", typeof(Int32))});
  17.             name.Rows.Add(new object[] { "Fielding", "William", 0 });
  18.             name.Rows.Add(new object[] { "Williams", "Arthur", 1 });
  19.             name.Rows.Add(new object[] { "Zuchini", "Theodore", 2 });
  20.             city = ds.Tables.Add("City/State");
  21.             city.Columns.AddRange(new DataColumn[] {new DataColumn("City", typeof(string)), new DataColumn("Owner", typeof(Int32)), new
  22. DataColumn("State", typeof(string))});
  23.             city.Rows.Add(new object[] { "Atlanta", 0, "Georgia" });
  24.             city.Rows.Add(new object[] { "Boston", 1, "Mass." });
  25.             city.Rows.Add(new object[] { "Tampa", 2, "Fla." });

  26.             FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType();
  27.             cb.DataSource = ds;
  28.             cb.ShowButton = true;
  29.             cb.DataMember = "City/State";
  30.             cb.DataTextField = "city";
  31.             cb.DataValueField = "city";
  32.             cb.UseValue = true;
  33.             FpSpread1.ActiveSheetView.Cells[0, 0].CellType = cb;
复制代码
回复 使用道具 举报
xxwood
初级会员   /  发表于:2012-2-14 10:24:00
地板
问题一依旧,我选择了列头,但就是无法指定CellType,选什么都自动变回none,很邪门啊。但是已经不是问题了,我既然要动态设置下拉框的数据源,就不用在设计器里设置了。实际上问题二就解决了问题一。

问题二的代码试验成功!多谢!顺便说一句,FpSpread1.ActiveSheetView.Cells[0, 0].CellType = cb 只是指定了第一行为下拉框,应该用FpSpread1.ActiveSheetView.Columns[0].CellType = cb; 卖弄一下
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-2-14 10:38:00
5#

回复 4# xxwood 的帖子

好的
回复 使用道具 举报
weizebin
论坛元老   /  发表于:2013-4-17 16:00:00
6#
回复 5楼iceman的帖子

您好,版主,请问下如何获取下拉框所选中的值呢。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-4-17 19:24:00
7#
回复 6楼weizebin的帖子

通过获取该单元格的 Text 可以给获得 Combo 值。
设设置代码:


  1.                 FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType();
  2.                 cb.Items = new string[] { "1", "2", "3" };

  3.                 this.FpSpread1.Sheets[0].Columns[0].CellType = cb;
  4.                 FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType();
  5.                 cb.Items = new string[] { "1", "2", "3" };


复制代码


选择之后获取代码:

  1.                 string combotext = this.FpSpread1.Sheets[0].Cells[0, 0].Text;
复制代码
回复 使用道具 举报
weizebin
论坛元老   /  发表于:2013-4-18 09:14:00
8#
回复 7楼iceman的帖子

好的,明白了。谢谢咯,
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-4-18 16:13:00
9#
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部