请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

sie

初级会员

40

主题

96

帖子

314

积分

初级会员

积分
314

活字格认证

sie
初级会员   /  发表于:2014-1-20 14:47  /   查看:6940  /  回复:7
C1TrueDBGrid可以设置指定区域或者设置某行号,列号的style吗?

7 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-1-20 18:03:00
沙发
回复 1楼sie的帖子

sie 你好,
可以通过以下代码设置特定单元格的style:

  1.             C1.Win.C1TrueDBGrid.Style S = new C1.Win.C1TrueDBGrid.Style();
  2.             Font myfont;

  3.             myfont = new Font(S.Font, FontStyle.Bold);
  4.             S.Font = myfont;
  5.             this.c1TrueDBGrid1.AddRegexCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S, "Computer");
复制代码
回复 使用道具 举报
sie
初级会员   /  发表于:2014-1-21 17:55:00
板凳
回复 2楼iceman的帖子

这是对所有单元格按contents设置style的吧,有没有可以设置指定区域的办法,比如4行4列,我想设置第2列的第2到第4行有没有办法。或者指定某一个单元格,cellstyleflag.currentcell并不能达到我想要的效果。flexgrid里还有setcellstyle的方法,truedbgrid就没有吗
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-1-22 10:18:00
地板
回复 3楼sie的帖子

抱歉,TrueDB Grid 无法指定某一范围单元格的 Style,它的设置行为通过文本内容及功能(标题、表头)进行设置的。

我会把这个问题提交给产品组,看能否有好的解决方法。

谢谢
回复 使用道具 举报
sie
初级会员   /  发表于:2014-1-22 16:50:00
5#
回复 4楼iceman的帖子

CellStyleFlag.AllCells这种模式,行列特别多的话效率如何,能不能对指定列的所有单元格进行contents的匹配?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-1-22 18:25:00
6#
回复 5楼sie的帖子

匹配所有内容代码如下:

  1.         public Form1()
  2.         {
  3.             InitializeComponent();

  4.             var ds = new DataSet();

  5.             DataTable dt = new DataTable();

  6.             dt.Columns.Add("B");
  7.             dt.Columns.Add("A");
  8.             dt.Columns.Add("D");
  9.             dt.Columns.Add("C");
  10.             dt.Rows.Add("test", "test", "test", "test");

  11.             this.c1TrueDBGrid1.DataSource = dt;

  12.             C1.Win.C1TrueDBGrid.Style S = new C1.Win.C1TrueDBGrid.Style();
  13.             Font myfont;
  14.             myfont = new Font(S.Font, FontStyle.Bold);
  15.             S.Font = myfont;
  16.             this.c1TrueDBGrid1.AddRegexCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S, ".*");
  17.         }
复制代码
回复 使用道具 举报
sxyweiren
中级会员   /  发表于:2014-1-24 11:18:00
7#
回复 6楼iceman的帖子

用FetchRowStyle配合FetchCellStyle就可以了。

插楼问一下,如何控制EditMask=“0000/00/00”的单元格入力只能入力半角数字?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-1-24 16:28:00
8#
回复 7楼sxyweiren的帖子

不好意思,TrueDBGrid 没有提供对全角半角输入的控制,提供一段全角半角转换的方法也许对你有帮助:

  1. void c1TrueDBGrid1_AfterColEdit(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
  2.         {
  3.             int rowindex = this.c1TrueDBGrid1.Row;
  4.             int colindex = e.ColIndex;

  5.             ToDBC(this.c1TrueDBGrid1[rowindex, colindex].ToString());
  6.         }

  7.         // /全角空格为12288,半角空格为32
  8.         // /其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
  9.         public static String ToDBC(String input)
  10.         {
  11.             char[] c = input.ToCharArray();
  12.             for (int i = 0; i < c.Length; i++)
  13.             {
  14.                 if (c[i] == 12288)
  15.                 {
  16.                     c[i] = (char)32;
  17.                     continue;
  18.                 }
  19.                 if (c[i] > 65280 &amp;&amp; c[i] < 65375)
  20.                     c[i] = (char)(c[i] - 65248);
  21.             }
  22.             return new String(c);
  23.         }


  24.         public static String ToSBC(String input)
  25.         {
  26.             // 半角转全角:
  27.             char[] c = input.ToCharArray();
  28.             for (int i = 0; i < c.Length; i++)
  29.             {
  30.                 if (c[i] == 32)
  31.                 {
  32.                     c[i] = (char)12288;
  33.                     continue;
  34.                 }
  35.                 if (c[i] < 127)
  36.                     c[i] = (char)(c[i] + 65248);
  37.             }
  38.             return new String(c);
  39.         }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部