Friday, July 04, 2008  



 FarPoint Technologies
 (800) 645-5913

 fpsales@fpoint.com



     
 »Spread for Windows Forms » Product Tour » Managing Data » Validating User Input

Previous Validating User Input Next

You can validate the contents of the cell in a number of ways. Some validation is performed by the control, based on the type of cell. Most often, to validate the input from a user, you can look for an event and run some validation routine based on the occurrence of that event.

  Back to Top
 Automatic Cell Validation
You can use several of Spread's cell types to automatically validate data as it is being entered by the user. For example, you can set a number cell type that will only allow the input of valid numbers and set the maximum and minimim values that may be entered by the user.

// Create a numeric cell
FarPoint.Win.Spread.CellType.NumberCellType nmbrCell = new FarPoint.Win.Spread.CellType.NumberCellType();
nmbrCell.MinimumValue = 1;
nmbrCell.MaximumValue = 10;
fpSpread1.ActiveSheet.Cells[1,1].CellType = nmbrCell;

' Create a numeric cell
Dim nmbrCell As New FarPoint.Win.Spread.CellType.NumberCellType()
nmbrCell.MinimumValue = 1
nmbrCell.MaximumValue = 10
FpSpread1.ActiveSheet.Cells(1,1).CellType = nmbrCell


  Back to Top
 Checking Changed Cell Data
For instance, the Changed event in the SheetView class notifies your application that the user has left edit mode and the contents of the cell has changed.

For more thorough validation, to handle the case where a user pastes a value from the Clipboard as opposed to typing in a value, use the Changed event on the data model (DefaultSheetDataModel class). This is a good way to evaluate the contents of a cell after it has been edited, and throw an error message or revert to original value if the data in the cell is not valid.


  Back to Top
 Checking Validity by Cell Type
Another simple way to check whether the user enters data that is valid based on the cell type is by using the IsValid method in the cell type classes.

The IsValid method determines whether the specified value can be converted to a appropriate value and is between the minimum and maximum allowed values.

// Determine if a valid date
FarPoint.Win.Spread.CellType.DateTimeCellType dt = new FarPoint.Win.Spread.CellType.DateTimeCellType();
bool b;
b = dt.IsValid(fpSpread1.ActiveSheet.Cells[0, 0].Value);

' Determine if a valid date
Dim dt As New FarPoint.Win.Spread.CellType.DateTimeCellType()
Dim b As Boolean
b = dt.IsValid(FpSpread1.ActiveSheet.Cells(0, 0).Value)


Previous Validating User Input Next

    
 Have a question?
Have a Question? Ask Us!
Subscribe to the RSS feed!RSS Subscribe
 

 
SD Times 'TOP 100' Industry Innovator - Read the press release (pdf)

Tour Home
Overview
Appearance
User Interaction
Cell Types
Formulas
Managing Data
Data Binding
Import/Export
Printing
Keyboard Interaction
Shapes
Models
Spread Designer
 
Map

Copyright © 1991-2007 FarPoint Technologies, Inc. All rights reserved. All names are property of their respective owners.