We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to mimic the Excel-like behavior for the cells that have the Format string?

Solution

In Excel, when the current cell enters into the edit mode it has the Value string and not the formatted string. The Excel formula bar always displays the Value String and not the formatted string. These behaviors can be achieved in the GridControl by installing a handler for CurrentCellInitializeControlText event and by setting the ControlText to Value string instead of the formatted string. This sets the GridAwareTextBox with value string consistently.

The following code example is for handling the CurrentCellInitializeText event.

C#

 

VB

 

Other different behaviors and options

GridAwareTextBox always with FormattedText

The GridAwareTextBox is implemented by following a consistent pattern and it always displays the .Text. When the CurrentCell is activated and GridCurrentCell is changed, the GridAwareTextBox text is set with the CurrentCell.Renderer.ControlText that is the formatted string, since by default the ControlText is initialized with the formatted text. So when you press Escape key while editing a cell, the GridAwareTextBox is again set with .Text that is not the formatted text. When you want to display the FormattedText consistently in the GridAwareTextBox then you can create sub class for the GridAwareTextBox, override the GridCurrentCellRejectedChanges and set the .FormattedText instead of the .Text

The following code example is for GridCurrentCellRejectedChanges event.

C#

 

VB

Parsing Formats

To save the underlying cell value from the formatted text, the ParseCommonFormats / SaveCellFormattedText event can be handled. The attached sample populates Text with formats when you miss any format character and also parses the formatted string and saves the underlying cell value, in the ParseCommonFormats event handler.

 

C#

 

VB

 

Sample

 

http://www.syncfusion.com/downloads/support/directtrac/general/WF-15698_How_to_mimic_Excel_like_behavior_for_cells_that_has_Format_string1979433900.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
4097 02/18/2015 03/19/2015 Windows Forms GridAwareTextBox
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.