找回密码
 立即注册

QQ登录

只需一步,快速开始

sucsy

高级会员

3

主题

8

帖子

1931

积分

高级会员

积分
1931

活字格认证

最新发帖
sucsy
高级会员   /  发表于:2015-5-12 10:55  /   查看:6128  /  回复:7
1、设置sheet为Protect=true后无法调整列宽。如不设置为protect则无法将单元格Locked。
2、可否设置某一列可自适应区域宽度?类似Grid中为列设置宽度为*的效果。

7 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-5-12 15:17:00
沙发
回复 1楼sucsy的帖子

可以先调整行列宽度,再进行锁定,方法如下:

  1.         private void button1_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             int columnCount = this.gcSpreadSheet1.ActiveSheet.ColumnCount;
  4.             int rowCount = this.gcSpreadSheet1.ActiveSheet.RowCount;
  5.             for (int i = 0; i < columnCount; i++)
  6.             {
  7.                 this.gcSpreadSheet1.AutoFitColumn(i);
  8.             }

  9.             for (int j = 0; j < rowCount; j++)
  10.             {
  11.                 this.gcSpreadSheet1.AutoFitRow(j);
  12.             }
  13.             gcSpreadSheet1.ActiveSheet.Protect = true;


  14.         }
复制代码
回复 使用道具 举报
sucsy
高级会员   /  发表于:2015-5-12 16:39:00
板凳
设置了Protect后可否可以设置 “能够手动调整列宽”呢?
因为部分单元格可以编辑,一旦内容过多就无法显示全部内容,目前列宽和行高在Protect后都无法调整。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-5-12 18:14:00
地板
回复 3楼sucsy的帖子

如果设置Protect属性,表单任何属性都不能更改。

明天我会继续跟进这个问题,看是否有完善的解决方法。
回复 使用道具 举报
sucsy
高级会员   /  发表于:2015-5-23 09:01:00
5#
能否在不设置Protect=true的情况下Lock指定单元格?
protect以后很多事件都不可用了,并且我只是个别单元格需要锁定。
回复 使用道具 举报
sucsy
高级会员   /  发表于:2015-5-23 11:52:00
6#
问题已经解决了,可以使用“EditStarting ”事件来处理
  1. protected void BindData()
  2.         {
  3.             this.grdItems.ActiveSheet.CellChanged -= new EventHandler<CellChangedEventArgs>(ActiveSheet_CellChanged);
  4.             this.grdItems.EditStarting -= new EventHandler<GrapeCity.Windows.SpreadSheet.UI.EditCellStartingEventArgs>(grdItems_EditStarting);
  5.             this.grdItems.AutoRefresh = false;
  6.             this.grdItems.SuspendCalcService();
  7.             this.grdItems.SuspendEvent();
  8.             CreateData();
  9.             this.grdItems.ResumeEvent();
  10.             this.grdItems.ResumeCalcService();
  11.             this.grdItems.AutoRefresh = true;
  12.             App.DoEvents();
  13.             this.grdItems.ActiveSheet.CellChanged += new EventHandler<CellChangedEventArgs>(ActiveSheet_CellChanged);
  14.             this.grdItems.EditStarting += new EventHandler<GrapeCity.Windows.SpreadSheet.UI.EditCellStartingEventArgs>(grdItems_EditStarting);           
  15.         }
  16.         void grdItems_EditStarting(object sender, GrapeCity.Windows.SpreadSheet.UI.EditCellStartingEventArgs e)
  17.         {
  18.             if (e.Column == 8 || e.Column == 10)
  19.             {
  20.                 e.Cancel = true;
  21.             }
  22.             else
  23.             {
  24.                 Row row = grdItems.ActiveSheet.Rows[e.Row];
  25.                 if (row.Locked)
  26.                 {
  27.                     e.Cancel = !(e.Column == 1 || e.Column == 9);
  28.                 }
  29.             }
  30.         }
复制代码

评分

参与人数 1金币 +300 收起 理由
iceman + 300 分享问题解决方法

查看全部评分

回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-5-25 13:35:00
7#
回复 6楼sucsy的帖子

好的,为了表示感谢你的反馈,给您分发 300 金币。可以用于兑换论坛奖品。
金币规则:点击进入
礼品列表:点击进入
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-5-26 09:28:00
8#
回复 1楼sucsy的帖子

为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢   

评分

参与人数 1满意度 +5 收起 理由
sucsy + 5 感谢解答

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部