找回密码
 立即注册

QQ登录

只需一步,快速开始

raul1122

中级会员

42

主题

155

帖子

980

积分

中级会员

积分
980

活字格认证微信认证勋章

[已处理] 单元格焦点问题

raul1122
中级会员   /  发表于:2012-6-17 16:47  /   查看:11495  /  回复:19
请问spread可以再后台给某个单元格焦点吗?
另外对于类型是combox的单元格,是否有combox_selectchanged类似事件?

19 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2012-6-18 10:23:00
沙发
回复 1楼raul1122的帖子

问题1:可以通过 sheetview 下属性 ActiveRow 和 ActiveColumn 属性设置。
问题2:可以通过 ComboBoxCellType 下属性 AutoPostBack 设置为 true,通过 FpSpread1_ButtonCommand 事件捕捉。
以上问题测试代码如下:

  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             if (IsPostBack)
  4.                 return;
  5.             this.FpSpread1.Sheets[0].ActiveColumn= 2;
  6.             this.FpSpread1.Sheets[0].ActiveRow = 1 ;

  7.             string[] cbstr;
  8.             string[] strval;
  9.             cbstr = new String[] { "One", "Two", "Three" };
  10.             strval = new String[] { "1", "2", "3" };
  11.             FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType();
  12.             cb.Items = cbstr;
  13.             cb.ShowButton = true;
  14.             cb.AutoPostBack = true;
  15.             FpSpread1.ActiveSheetView.Columns[0].CellType = cb;
  16.             FpSpread1.ActiveSheetView.DataModel.SetValue(0, 0, 1);
  17.         }

  18.         protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
  19.         {

  20.         }
复制代码
回复 使用道具 举报
婧友521
银牌会员   /  发表于:2012-6-18 15:07:00
板凳
sheetview 下属性 ActiveRow 和 ActiveColumn 属性设置,具体怎样得到焦点呢? 急!!,麻烦给点后台代码提示????
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-18 15:47:00
地板
回复 3楼婧友521的帖子
楼主是想获取焦点所在 Cell 行列索引还是,获取焦点所在 Cell 对象?

  1. if (IsPostBack)
  2.                 return;
  3.             this.FpSpread1.Sheets[0].ActiveColumn= 2;
  4.             this.FpSpread1.Sheets[0].ActiveRow = 1 ;

  5.             //获取行列索引
  6.             int columnIndex = this.FpSpread1.Sheets[0].ActiveColumn;
  7.             int rowIndex = this.FpSpread1.Sheets[0].ActiveRow;
  8.             //获取焦点所在单元格
  9.             FarPoint.Web.Spread.Cell activeCell = this.FpSpread1.Sheets[0].Cells[columnIndex, rowIndex];
复制代码
回复 使用道具 举报
婧友521
银牌会员   /  发表于:2012-6-18 15:54:00
5#
我是想把焦点给当前活跃单元格的下一个单元格? 后台怎样实现?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-18 16:04:00
6#
回复 5楼婧友521的帖子

判断方法如下:
  1.         
  2. protected void Button1_Click(object sender, EventArgs e)
  3.         {
  4.             this.FpSpread1.SaveChanges();
  5.             if (this.FpSpread1.Sheets[0].ActiveRow == this.FpSpread1.Sheets[0].RowCount - 1 && this.FpSpread1.Sheets[0].ActiveColumn == this.FpSpread1.Sheets[0].ColumnCount - 1)
  6.             {
  7.                 return;
  8.             }
  9.             if (this.FpSpread1.Sheets[0].ActiveColumn==this.FpSpread1.Sheets[0].ColumnCount-1)
  10.             {
  11.                 this.FpSpread1.Sheets[0].ActiveRow += 1;
  12.                 this.FpSpread1.Sheets[0].ActiveColumn = 0;
  13.             }
  14.             else
  15.             {
  16.                 this.FpSpread1.Sheets[0].ActiveColumn += 1;
  17.             }
  18.         }
复制代码
回复 使用道具 举报
婧友521
银牌会员   /  发表于:2012-6-18 17:51:00
7#
我想问一下, 怎样通过GetCellFromTag() 这个方法来得到某个指定的单元格的行索引和列索引?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-18 18:09:00
8#
回复 7楼婧友521的帖子

测试代码如下:

  1. //存取 tag 列表

  2.         List<string> _tagList = new List<string>();

  3.         protected void Page_Load(object sender, EventArgs e)

  4.         {

  5.             if (IsPostBack)
  6.                 return;
  7.             this.FpSpread1.Sheets[0].RowCount = 2;
  8.             this.FpSpread1.Sheets[0].ColumnCount = 2;

  9.             for (int i = 0; i < 2; i++)
  10.             {
  11.                 for (int j = 0; j < 2; j++)
  12.                 {
  13.                     string tag="行" + i.ToString() + "列" + j.ToString();
  14.                     this.FpSpread1.Sheets[0].SetTag(i, j, tag);
  15.                     _tagList.Add(tag);
  16.                 }
  17.             }

  18.             //循环列表,取单元格
  19.         foreach (var tag in _tagList)
  20.             {
  21.                FarPoint.Web.Spread test= this.FpSpread1.Sheets[0].GetCellFromTag(null,tag).Text = tag;
  22.             }
  23.         }
复制代码
回复 使用道具 举报
婧友521
银牌会员   /  发表于:2012-6-18 18:16:00
9#
我是想GetCellFromTag()方法取得某个单元格对象,然后通过该对象得到它的行列索引?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-19 10:19:00
10#
回复 9楼婧友521的帖子

获取方法如下:

  1.             this.FpSpread1.Sheets[0].Cells[0, 0].Tag = &quot;tag&quot;;
  2.             FarPoint.Web.Spread.Cell tagCell = this.FpSpread1.Sheets[0].GetCellFromTag(null, &quot;tag&quot;);

  3.             int rowIndex = tagCell.Row.Index;
  4.             int colIndex = tagCell.Column.Index;
复制代码
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部