Class GridCurrencyTextBoxCellRenderer
Implements the renderer part of a currency cell that handles currency input and validation.
Inheritance
Inherited Members
Namespace: Syncfusion.Windows.Forms.Grid
Assembly: Syncfusion.Grid.Windows.dll
Syntax
public class GridCurrencyTextBoxCellRenderer : GridStaticCellRenderer, IQueryFocusInside, IGridDropDownCell, IPopupParent, IPopupItem, IDisposable
Remarks
The CurrencyTextBox is derived from the text box and provides all the functionality of a text box and adds additional functionality of its own.
Collecting currency input in a consistent format requires a alot of validation code that needs to be built into the application when using the Windows Forms text box control. The CurrencyTextBox includes all this logic into its methods and properties and makes it easy for the developer and the end user to collect and enter currency data.
The CurrencyTextBox is also closely tied to the globalization settings of the operating system for Currency related properties. Please refer to the System.Globalization.NumberFormatInfo class for a detailed explanation of globalization and Currency related attributes.
Use the CurrencyEdit (GridCurrencyEditInfo) property of a GridStyleInfo to change currency edit properties for a cell.
The following table lists some characteristics about the Currency cell type:
Item | Description |
---|---|
CellType | Currency |
Renderer | GridCurrencyTextBoxCellRenderer |
Model | GridCurrencyTextBoxCellModel |
XP Themes Support | NA |
Interactive | Edit with Text Input |
Control | GridCurrencyTextBox |
Floating Support | Both |
Base Type | GridStaticCellRenderer |
The cell's behavior and appearance can be customized with the following properties of the GridStyleInfo class:
PropertyName | Description |
---|---|
AutoSize (System.Boolean) | Gets / sets if the cell height should automatically increase when the edited text does not fit into the cell and WrapText is True. If WrapText is False, AutoSize will affect the column width. (Default: false) |
BaseStyle (System.String) | The base style for this style instance with default values for properties that are not initialized for this style object. (Default: String.Empty) |
Borders (GridBordersInfo) | Top, left, bottom, and right border settings. (Default: GridBordersInfo.Default) |
CellAppearance (GridCellAppearance) | Specifies if cell edges shall be drawn raised, sunken, or flat (default). (Default: GridCellAppearance.Flat) |
CellTipText (System.String) | ToolTip text to be displayed when user hovers mouse over cell. (Default: String.Empty) |
CellType (System.String) | Currency (Default: Text Box) |
CellValue (System.Object) | This property holds the cell value. Although the cell value is typically a string, it can also be any other primitive type such as int, byte, enum, or any custom type that is derived from System.Object. (Default: String.Empty) |
CellValueType (System.Type) | Specifies the preferred System.Type for cell values. When you assign a value to the GridStyleInfo object, the value will be converted to this type. If the value cannot be converted, Error will contain error information. (Default: NULL) |
CultureInfo (System.Globalization.CultureInfo) | The culture information holds rules for parsing and formatting the cell's value. (Default: NULL) |
CurrencyEdit (GridCurrencyEditInfo) | A nested object with currency text box properties for a cell. (Default: GridCurrencyEditInfo.Default) |
Enabled (System.Boolean) | Specifies if the cell can be activated as current cell or if the cell should be skipped when moving the current cell. (Default: True) |
Error (System.String) | Holds error information if a value could not be converted to the System.Type specified with CellValueType. (Default: String.Empty) |
FloatCell (System.Boolean) | Gets / sets if text can float into the boundaries of a neighboring cell. (Default: True) |
FloodCell (System.Boolean) | Gets / sets if this cell can be flooded by a previous cell. (Default: True) |
Font (GridFontInfo) | The font for drawing text. (Default: GridFontInfo.Default) |
Format (System.String) | Gets / sets the format mask for formatting the cell value. You can specify numeric format strings, Date format strings or enumeration format strings as discussed in the section "Format Specifiers and Format Providers" of the .NET Framework Developers Guide (see ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconformatspecifiersformatproviders.htm). (Default: String.Empty) |
Interior (BrushInfo) | Lets you specify a solid backColor, gradient, or pattern style with both back and foreColor for a cell's background. (Default: SystemColors.Window) |
MaxLength (System.Int32) | Limits the number of characters the user can type into the cell. Note: When selecting a text from a choice list or when pasting text, the text can be longer. Additional validation is necessary on your side. (Default: 0) |
MergeCell (GridMergeCellDirection) | Specifies merge behavior for a individual cell when merging cell's features have been enabled in a GridModel with MergeCellsMode. (Default: GridMergeCellDirection.None) |
ReadOnly (System.Boolean) | Specifies if cell contents can be modified by the user. You can programmatically change Read-only cells by setting DiscardReadOnly to True. (Default: False) |
Text (System.String) | Gets / sets the value as a string. If a CellValueType is specified, the text will be parsed and converted to the type specified with CellValueType using any CultureInfo information. (Default: String.Empty) |
TextColor (System.Drawing.Color) | Lets you specify the color for drawing the cell text. (Default: SystemColors.WindowText) |
TextMargins (GridMarginsInfo) | Holds text margins in pixels. When drawing a cell, this specifies the empty area between the text rectangle and the client rectangle of the cell without borders and cell buttons. (Default: GridMarginsInfo.Default) |
Constructors
GridCurrencyTextBoxCellRenderer(GridControlBase, GridCellModelBase)
Initializes a new GridCurrencyTextBoxCellRenderer object for the given GridControlBase and GridCellModelBase.
Declaration
public GridCurrencyTextBoxCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
Parameters
Type | Name | Description |
---|---|---|
GridControlBase | grid | The GridControlBase that display this cell renderer. |
GridCellModelBase | cellModel | The GridCellModelBase that holds data for this cell renderer that should be shared among views. |
Remarks
References to GridControlBase, and GridCellModelBase will be saved.
Methods
CanCopy()
Determines whether current cell can be copied to clipboard.
Declaration
public override bool CanCopy()
Returns
Type | Description |
---|---|
System.Boolean | True if copy is supported; otherwise False. |
Overrides
CanCut()
Determines whether current cell can be cut to clipboard.
Declaration
public override bool CanCut()
Returns
Type | Description |
---|---|
System.Boolean | True if cut is supported; otherwise False. |
Overrides
CanPaste()
Determines whether current cell can be pasted from clipboard.
Declaration
public override bool CanPaste()
Returns
Type | Description |
---|---|
System.Boolean | True if paste is supported; otherwise False. |
Overrides
Dispose(Boolean)
Unwires any events subscribed from focusControl.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Overrides
Remarks
See the documentation for the System.ComponentModel.Component class and its Dispose member.
InitializeControlText(Object)
Initializes ControlText based on the specified cell value.
Declaration
protected override void InitializeControlText(object controlValue)
Parameters
Type | Name | Description |
---|---|---|
System.Object | controlValue | The cell value. See the CellValue of the GridStyleInfo class. |
Overrides
Remarks
The default behavior of this method is to call GetFormattedText(Object) of the StyleInfo object and then raise a CurrentCellInitializeControlText event.
The user can catch the event and change the ControlText property of the GridCurrentCellInitializeControlTextEventArgs object.
OnActivated()
This is called after the activating event and notifies that at this time the current cell has now become the active current cell.
Declaration
protected override void OnActivated()
Overrides
OnBeginEdit()
Called from GridCurrentCell.BeginEdit. Checks if cell renderer support in place editing. If in-place editing is supported, Syncfusion.Windows.Forms.Grid.GridCellRendererBase.SetHasFocusControl(System.Boolean) is called which triggers OnHasFocusControlChanged() and initiates repainting the cell. In your overridden OnDraw(Graphics, Rectangle, Int32, Int32, GridStyleInfo) method, you should then check ShouldDrawFocused(Int32, Int32).
Declaration
protected override void OnBeginEdit()
Overrides
OnClick(Int32, Int32, MouseEventArgs)
This is called from GridSelectCellsMouseController when the user double-clicks inside a cell.
Declaration
protected override void OnClick(int rowIndex, int colIndex, MouseEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | The row index. |
System.Int32 | colIndex | The column index. |
System.Windows.Forms.MouseEventArgs | e | A System.Windows.Forms.MouseEventArgs with data about the mouse event. |
Overrides
OnDoubleClick(Int32, Int32, MouseEventArgs)
Declaration
protected override void OnDoubleClick(int rowIndex, int colIndex, MouseEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | |
System.Int32 | colIndex | |
System.Windows.Forms.MouseEventArgs | e |
Overrides
OnDraw(Graphics, Rectangle, Int32, Int32, GridStyleInfo)
This method is called from the cell renderer's draw method to draw the contents of the client bounds for the cell, e.g. the text for a static cell.
Declaration
protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Graphics | g | Points to the device context. |
System.Drawing.Rectangle | clientRectangle | Specifies the client rectangle. It is the cell rectangle without buttons and borders. |
System.Int32 | rowIndex | Specifies the row id. |
System.Int32 | colIndex | Specifies the column id. |
GridStyleInfo | style | A reference to the style object of the cell. |
Overrides
Remarks
When drawing cells, it is necessary to determine if the specified cell (with rowIndex and colIndex) is the current cell and if it is active.
If your control is associated with a control and supports in-place editing and the specified cell is the current cell, you should position the control. Take a look at the GridTextBoxCellRenderer implementation of this method for an example.
Otherwise, you can simply draw the cell.
OnHasFocusControlChanged()
Override this method if your cell renderer supports in-place editing and you want to do any custom initialization at this point before cell gets redrawn.
Declaration
protected override void OnHasFocusControlChanged()
Overrides
Remarks
The default behavior of this virtual method is to force a redraw of the current cell. A cell can then initialize an edit control and set focus in the OnDraw method call.
OnInitialize(Int32, Int32)
This method gets called from the cell renderer's initialize method. Override this method if you need to any initialization for the current cell.
Declaration
protected override void OnInitialize(int rowIndex, int colIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | The row index. |
System.Int32 | colIndex | The column index. |
Overrides
OnKeyDown(KeyEventArgs)
User pressed key down (similar to Control.OnKeyDown).
Declaration
protected override void OnKeyDown(KeyEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.KeyEventArgs | e | The System.Windows.Forms.KeyEventArgs |
Overrides
OnKeyPress(KeyPressEventArgs)
User pressed key (similar to Control.OnKeyPress).
Declaration
protected override void OnKeyPress(KeyPressEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.KeyPressEventArgs | e | A System.Windows.Forms.KeyEventArgs with data of the keyboard event. |
Overrides
OnLayout(Int32, Int32, GridStyleInfo, Rectangle, Rectangle[])
This method is called from PerformLayout to calculate the client rectangle given the inner rectangle of a cell and any boundaries of cell buttons.
Declaration
protected override Rectangle OnLayout(int rowIndex, int colIndex, GridStyleInfo style, Rectangle innerBounds, Rectangle[] buttonsBounds)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | The row index. |
System.Int32 | colIndex | The column index. |
GridStyleInfo | style | The GridStyleInfo object that holds cell information. |
System.Drawing.Rectangle | innerBounds | The System.Drawing.Rectangle with the inner bounds of a cell. |
System.Drawing.Rectangle[] | buttonsBounds | An array of System.Drawing.Rectangle with bounds for each cell button element. |
Returns
Type | Description |
---|---|
System.Drawing.Rectangle | A System.Drawing.Rectangle with the bounds. |
Overrides
OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs)
Allows custom formatting of a cell by changing its style object.
Declaration
public override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
GridPrepareViewStyleInfoEventArgs | e | Event data. |
Overrides
OnSaveChanges()
This method is called from GridCurrentCell.ConfirmChanges when the current cell was marked as modified. Any drop-downs have been closed at this time. It saves changes for the current cell.
Declaration
protected override bool OnSaveChanges()
Returns
Type | Description |
---|---|
System.Boolean | True if changes were saved successfully; False if no changes were saved. |
Overrides
OnSetControlText(String)
Called right after ControlText was set.
Declaration
protected override void OnSetControlText(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The ControlText |
Overrides
OnValidate()
This method is called from GridCurrentCell.Validate after GridCurrentCell.Validating event has been fired. The default version checks if the active text fits any criteria as specified in the style object: It can be parsed into a cell value and meets GridCellValidateValueInfo criteria.
Declaration
protected override bool OnValidate()
Returns
Type | Description |
---|---|
System.Boolean | True if the modified text is valid; False otherwise. |
Overrides
Paste()
Called when user initiates a clipboard paste and the grid has a current cell but no range is selected.
Declaration
public override bool Paste()
Returns
Type | Description |
---|---|
System.Boolean | True if successful; False if failed. |