[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
    [Expand]Conditional Formatting
    [Expand]Data Binding
    [Expand]Data Editing
    [Expand]Data Presentation
    [Expand]Export and Printing
      Examples: Formatting Values
      How to: Create a Custom Formatter to Substitute Boolean Values with Appropriate Strings
      How to: Format Column Values Using Standard Format Strings
      How to: Format Display Text in Grid's Cells Depending on Values in Other Cells
    [Expand]General Use
    [Expand]Layout View
    [Expand]Navigation and Selection
    [Expand]Skins and Look and Feel
    [Expand]Sorting and Grouping
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Create a Custom Formatter to Substitute Boolean Values with Appropriate Strings

The following example demonstrates how to substitute Boolean values in the XtraGrid's column with specific strings using a custom formatter. See the Custom Formatting topic for general information on creating custom formatters. Note that Boolean values can also be custom formatted via the grid's event (ColumnView.CustomColumnDisplayText).

In this example a custom formatter is created. It contains two internal variables that specify the strings that correspond to the true and false values. These are initialized with values in the custom formatter's constructor. The object's Format method inspects the current value to be formatted and returns an appropriate string. See the code below.

Consider the column shown in the image below. It is bound to a Boolean field containing values that specify whether or not a car has an automatic transmission.

This column can be made more informative by replacing the true and false values with the 'Automatic' and 'Manual' strings respectively . The code below shows how to assign the BooleanFormatter to this column.

The column's in-place editor must be a text editor, otherwise values will not be formatted. To use a text editor for in-place editing a RepositoryItemTextEdit object is assigned to the column's GridColumn.ColumnEdit property.

The image below displays the result.

Is this topic helpful?​​​​​​​