>>现有的列类型 如何限制长度以及录入的类型?
录入类型,通过Formatter来设置,
这个和Excel的使用方法相同。
限制长度,是使用DataValidator 功能实现的,使用方法也和Excel的DataValidator 相同。
- double dvalue = 12345.6789;
- gcSpreadSheet1.Sheets[0].Cells[0, 0].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter(GrapeCity.Windows.SpreadSheet.Data.FormatMode.StandardNumericMode, "c");
- gcSpreadSheet1.Sheets[0].Cells[0, 0].Value = dvalue;
- gcSpreadSheet1.Sheets[0].Cells[0, 1].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter(GrapeCity.Windows.SpreadSheet.Data.FormatMode.StandardDateTimeMode, "M");
- gcSpreadSheet1.Sheets[0].SetValue(0, 1, new DateTime(2011, 2, 9));
- gcSpreadSheet1.Sheets[0].Cells[0, 2].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter("m");
- gcSpreadSheet1.Sheets[0].SetValue(0, 2, new DateTime(2012, 10, 15));
- gcSpreadSheet1.Sheets[0].Cells[0, 3].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter();
- gcSpreadSheet1.Sheets[0].SetValue(0, 3, new DateTime(2012, 10, 15));
- gcSpreadSheet1.Sheets[0].Cells[0, 4].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter(GrapeCity.Windows.SpreadSheet.Data.FormatMode.CustomMode, "#.#%");
- gcSpreadSheet1.Sheets[0].SetValue(0, 4, 1);
- gcSpreadSheet1.Sheets[0].Cells[1, 0].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter(GrapeCity.Windows.SpreadSheet.Data.FormatMode.CustomMode, "[>2]0.0;[<-3]0.0;zero;");
- gcSpreadSheet1.Sheets[0].SetValue(1, 0, 3);
- gcSpreadSheet1.Invalidate();
复制代码- this.gcSpreadSheet1.ActiveSheet.Columns[0].DataValidator = DataValidator.CreateTextLengthValidator(ComparisonOperator.LessThan, 10, null);
- this.gcSpreadSheet1.ValidationError += new EventHandler<GrapeCity.Windows.SpreadSheet.UI.ValidationErrorEventArgs>(gcSpreadSheet1_ValidationError);
- void gcSpreadSheet1_ValidationError(object sender, GrapeCity.Windows.SpreadSheet.UI.ValidationErrorEventArgs e)
- {
- MessageBox.Show("The text length is invalid, please try again");
- }
复制代码 |