Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Collapse]Examples
    [Expand]Data Binding
    [Expand]Data Editing
    [Expand]Data Presentation
    [Expand]Export and Printing
    [Expand]Filtering
    [Collapse]Formatting
      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]Master-Detail
    [Expand]Miscellaneous
    [Expand]Navigation and Selection
    [Expand]Painting
    [Expand]Skins and Look and Feel
    [Expand]Sorting and Grouping
    [Expand]Summaries
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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.

How would you rate this topic?​​​​​​​