找回密码
 立即注册

QQ登录

只需一步,快速开始

chcchb
论坛元老   /  发表于:2013-7-2 11:25  /   查看:4905  /  回复:3
ComboBoxCellType定义和绑定数据源代码如下:
  1. Dim cdct As New FarPoint.Web.Spread.ComboBoxCellType
  2.             cdct.AllowWrap = False
  3.             cdct.ShowButton = True
  4.             cdct.UseValue = True
  5.             cdct.DataTextField = "PARAM2"
  6.             cdct.DataValueField = "PARAM1"

  7.             cdct.DataSource = dt
  8.             sheet.Columns(7).CellType = cdct
复制代码


在FpSpread1绑定数据时的代码如下:
  1. FpSpread1.DataSource = dt
  2.             FpSpread1.DataBind()
  3.             sheet.Rows.Count = dt.Rows.Count
  4.             
  5. For iRowCount As Integer = 0 To sheet.Rows.Count - 1
  6.            sheet.DataModel.SetValue(iRowCount, 7, [color=Red]sheet.Cells(iRowCount, 7).Value[/color])
  7. Next

复制代码

这里我用SetValue来设置,调试时跟踪了下红色标记的值在变化,但是实际显示时,ComboBoxCellType都是第一条数据

3 个回复

倒序浏览
chcchb
论坛元老   /  发表于:2013-7-2 16:43:00
沙发
设置值的方法找到了.

不过现在的问题是,画面载完后,最终都为第一条数据. 正确的选择结果一闪而过.
回复 使用道具 举报
chcchb
论坛元老   /  发表于:2013-7-2 17:05:00
板凳
汗,发现问题了,原来是cdct.ShowButton = True  这个属性设置导致的.
设成true后,页面上看是有下拉框的,设成flase后,要双击才会出现下拉框
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-7-2 19:27:00
地板
回复 3楼chcchb的帖子

请通过以下代码测试:

  1. public partial class WebForm1 : System.Web.UI.Page
  2.     {
  3.         protected void Page_Load(object sender, EventArgs e)
  4.         {
  5.             if (IsPostBack)
  6.             {
  7.                 return;
  8.             }
  9.             InitSpread();

  10.         }

  11.         /// <summary>
  12.         /// 初始化 Spread
  13.         /// </summary>
  14.         private void InitSpread()
  15.         {

  16.             //获取 ComboboxCellType 数据源
  17.             DataSet ds = GetDataSet();

  18.             //设置 ComboBoxCellType
  19.             FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType();
  20.             cb.AllowWrap = true;
  21.             cb.DataSource = ds;
  22.             cb.ShowButton = true;
  23.             cb.DataMember = "Heros";
  24.             cb.DataTextField = "Name";
  25.             cb.DataValueField = "ID";
  26.             cb.UseValue = true;
  27.             cb.AutoPostBack = true;
  28.             cb.OnClientChanged = "alert('更改选项')";
  29.             FpSpread1.ActiveSheetView.Cells[0, 0].CellType = cb;
  30.             FpSpread1.ActiveSheetView.Cells[0, 0].Value = 1;
  31.         }

  32.         /// <summary>
  33.         /// 设置数据源
  34.         /// </summary>
  35.         /// <returns>ComboBoxCellType 使用的数据源</returns>
  36.         private DataSet GetDataSet()
  37.         {
  38.             DataSet ds = new System.Data.DataSet();
  39.             DataTable name;
  40.             name = ds.Tables.Add("Heros");
  41.             name.Columns.AddRange(new DataColumn[] {new DataColumn("Name", typeof(string)), new DataColumn("ID", typeof
  42. (Int32))});
  43.             name.Rows.Add(new object[] { "第一项", 0 });
  44.             name.Rows.Add(new object[] { "更改值项", 1 });
  45.             return ds;
  46.         }
  47.     }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部