找回密码
 立即注册

QQ登录

只需一步,快速开始

barrylei
中级会员   /  发表于:2011-5-27 09:22:00
地板
>另只有得到焦点的单元格才能设置成黄色.

代码如下,在CellEnter的时候设置用户想要的颜色,在CellLeave的时候恢复原来的颜色

  1.         private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             this.gcMultiRow1.RowCount = 5;
  4.             this.gcMultiRow1.CellEnter += new EventHandler<GrapeCity.Win.MultiRow.CellEventArgs>(gcMultiRow1_CellEnter);
  5.             this.gcMultiRow1.CellLeave += new EventHandler<GrapeCity.Win.MultiRow.CellEventArgs>(gcMultiRow1_CellLeave);
  6.         }

  7.         private Color temp = Color.Empty; //临时的变量用于Cache原来的颜色
  8.         private Color UserColor = Color.Yellow; // 用户期望设置成的颜色
  9.         void gcMultiRow1_CellEnter(object sender, GrapeCity.Win.MultiRow.CellEventArgs e)
  10.         {
  11.             temp = this.gcMultiRow1.CurrentCell.Style.BackColor; //进入Cell的时候把原来的颜色保留
  12.             this.gcMultiRow1.CurrentCell.Style.SelectionBackColor = UserColor;//进入Cell的时候,设置用户想要的颜色
  13.         }

  14.         void gcMultiRow1_CellLeave(object sender, GrapeCity.Win.MultiRow.CellEventArgs e)
  15.         {
  16.             this.gcMultiRow1.CurrentCell.Style.SelectionBackColor = temp; //离开Cell的时候,恢复Cell原来的颜色
  17.         }
复制代码
回复 使用道具 举报
barrylei
中级会员   /  发表于:2011-5-26 18:06:00
板凳
&gt;另只有得到焦点的单元格才能设置成黄色.

确认一下,这个需求的意识是不是,一个单元格得到焦点时,背景变成黄色,失去焦点时,背景又得回滚到原来的颜色?
回复 使用道具 举报
barrylei
中级会员   /  发表于:2011-5-26 17:59:00
沙发
在CellValidating事件里面,写下面的代码

  1.         private void gcMultiRow1_CellValidating(object sender, GrapeCity.Win.MultiRow.CellValidatingEventArgs e)
  2.         {
  3.             if (e.FormattedValue != null &amp;&amp; e.CellName == &quot;textBoxCell1&quot; &amp;&amp; e.FormattedValue.ToString().Length  &gt; 5)
  4.             {
  5.                 e.Cancel = true;
  6.                 MessageBox.Show(&quot;Error&quot;);
  7.             }

  8.         }
复制代码
回复 使用道具 举报
1234
您需要登录后才可以回帖 登录 | 立即注册
返回顶部