Spread 7 for WinForms 新引入了2 个新的 CellTypes:
- GcTextBoxCellType 文本输入
- GcDateTimeCellType 日期输入
- 本文
- 的功能进行说明:
现在你可以访问时间,月,日,年等字段,并单独进行设置。您可以设定不同的字段在GcDateTimeCell当单元格在编辑模式下,或者单元格不处于编辑模式时。单元格用“DisplayFields”绘制不处于编辑模式时.使用“Fields”绘制在编辑模式下单元格。
Using GcDateTimeCellType
1 格式字段:您可以使用GcDateTimeCellType的进行格式化“Fields”。字段基本上都是日期字段显示处于编辑模式时。要格式化这些字段,首先你需要设置字段对象,然后将它们添加到GcDateTimeCellType的Fields集合。
1: //Create Field objects
2: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayFieldInfo dayInfo = new DateDayFieldInfo();
3: dayInfo.BackColor = Color.Lavender;
4: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateMonthFieldInfo monthInfo = new DateMonthFieldInfo();
5: monthInfo.BackColor = Color.Azure;
6: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateYearFieldInfo yearInfo = new DateYearFieldInfo();
7: yearInfo.BackColor = Color.Crimson;
8: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateLiteralFieldInfo literalInfo= new DateLiteralFieldInfo();
9: literalInfo.Text = "/";
10: //Add to GcDateTimeCell's Fields Collection
11: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType gcDateTimecell= new GcDateTimeCellType();
12: gcDateTimecell.Fields.Add(monthInfo);
13: gcDateTimecell.Fields.Add(literalInfo);
14: gcDateTimecell.Fields.Add(dayInfo);
15: gcDateTimecell.Fields.Add(literalInfo);
16: gcDateTimecell.Fields.Add(yearInfo);
2. 格式化DisplayFields:类似地,你可以进行格式化DisplayFields。 DisplayFields单元格不处于编辑模式时显示的日期字段。例如,如果日期单元格不处于编辑模式,我们可以设置格式,如显示以零开头,日,月,文字和年度字段的背景色,前景色等。
1: //Create Field objects
2: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayDisplayFieldInfo day = new DateDayDisplayFieldInfo();
3: day.ShowLeadingZero = true;
4: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateMonthDisplayFieldInfo month = new DateMonthDisplayFieldInfo();
5: month.ShowLeadingZero = true;
6: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateYearDisplayFieldInfo year = new DateYearDisplayFieldInfo();
7: year.ShowLeadingZero = true;
8: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateLiteralDisplayFieldInfo lday = new DateLiteralDisplayFieldInfo();
9: lday.Text = "/";
10: //Add to GcDateTimeCell's DisplayFields Collection
11: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType gcDateTimecell= new GcDateTimeCellType();
12: gcDateTimecell.DisplayFields.Add(month);
13: gcDateTimecell.DisplayFields.Add(lday);
14: gcDateTimecell.DisplayFields.Add(day);
15: gcDateTimecell.DisplayFields.Add(lday);
16: gcDateTimecell.DisplayFields.Add(year)
17:
上面的代码显示效果截图如下:
3.ValidateMode属性:此单元格类型中的另一个重要特征是,它可以通过设置的ValidateMode属性验证用户的输入。
该属性有三个枚举:
- GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.Validate
- GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateEx
- GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateNone 如果设置为ValidationMode“ValidateEx”,它会执行严格的验证,例如,2月31日不允许使用的日期
1: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType datecell = new CellType.GcDateTimeCellType();
2: datecell.ValidateMode = GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateEx;
3: fpSpread1.Sheets[0].Cells[0, 0].CellType = datecell;
4:
源码下载: