Export (0) Print
Expand All

How to: Customize Data Formatting in the Windows Forms DataGridView Control

The following code example demonstrates how to implement a handler for the DataGridView::CellFormatting event that changes how cells are displayed depending on their columns and values.

Cells in the Balance column that contain negative numbers are given a red background. You can also format these cells as currency to display parentheses around negative values. For more information, see How to: Format Data in the Windows Forms DataGridView Control.

Cells in the Priority column display images in place of corresponding textual cell values. The Value property of the DataGridViewCellFormattingEventArgs is used both to get the textual cell value and to set the corresponding image display value.

No code example is currently available or this language may not be supported.

This example requires:

  • References to the System, System.Drawing, and System.Windows.Forms assemblies.

  • Bitmap images named highPri.bmp, mediumPri.bmp, and lowPri.bmp residing in the same directory as the executable file.

For information about building this example from the command line for Visual Basic or Visual C#, see Building from the Command Line (Visual Basic) or Command-line Building With csc.exe. You can also build this example in Visual Studio by pasting the code into a new project. Also see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.

© 2015 Microsoft