You can use a percent cell for displaying values as percentages and restricting inputs to percentage numeric values.
You use the PercentCellType class to set the percent cell and its properties.
Using Spin Buttons
By default, no spin buttons are shown, but you can display spin buttons in the side of the cell when the cell is in edit mode. You can set various spin functions using the properties of the PercentCellType that begin with the word Spin. Refer to Displaying Spin Buttons.
Using the Calculator
By default, in a percent cell, if you double-click on the cell in edit mode at run-time, a pop-up calculator appears. You can determine whether to allow this, and you can specify the text that displays on the OK and Cancel buttons. For more information, refer to Customizing the Pop-Up Calculator Control. To prohibit the popping up of the calculator, cancel the FpSpread SubEditorOpening event. Handle this event and set the Cancel argument of the SubEditorOpeningEventArgs to true.
For more information on the properties and methods of this cell type, refer to the PercentCellType class.
For more information on other editable cell types, refer to Working with Editable Cell Types.
Using the Properties Window
- At design time, in the Properties window, select the Spread component.
- Select the Sheets property.
- Click the button to display the SheetView Collection Editor.
- In the Members list, select the sheet in which the cells appear.
- In the property list, select the Cells property and then click the button to display the Cell, Column, and Row Editor.
- Select the cells for which you want to set the cell type.
- In the property list, select the CellType property and choose the Percent cell type.
- Expand the list of properties under the CellType property. Select and set these specific properties as needed.
- Click OK to close the Cell, Column, and Row Editor.
- Click OK to close the SheetView Collection Editor.
- Define the percent cell by creating an instance of the PercentCellType class.
- Assign the percent cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the PercentCellType object.
This example sets a cell to be a percent cell and displays an abbreviation (PRCNT) instead of the percent sign (%).
FarPoint.Win.Spread.CellType.PercentCellType prctcell = new FarPoint.Win.Spread.CellType.PercentCellType();
prctcell.PercentSign = "PRCNT";
prctcell.PositiveFormat = FarPoint.Win.Spread.CellType.PercentPositiveFormat.PercentSignBeforeWithSpace;
fpSpread1.ActiveSheet.Cells[1, 1].CellType = prctcell;
Dim prctcell As New FarPoint.Win.Spread.CellType.PercentCellType()
prctcell.PercentSign = "PRCNT"
prctcell.PercentPositiveFormat = FarPoint.Win.Spread.CellType.PercentPositiveFormat.PercentSignBeforeWithSpace
FpSpread1.ActiveSheet.Cells(1, 1).CellType = prctcell
Using the Spread Designer
- Select the cell or cells in the work area.
- In the property list, in the Misc category, select CellType. From the drop-down list, choose the Percent cell type. Now expand the CellType property and various properties are available that are specific to this cell type. Select and set those properties as needed.
- From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
Or right-click on the cell or cells and select Cell Type. From the list, select Percent. In the CellType editor, set the properties you need. Click Apply.