Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

DataGridViewDataErrorContexts Enumeration

Represents the state of a data-bound DataGridView control when a data error occurred.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[FlagsAttribute] 
public enum DataGridViewDataErrorContexts
/** @attribute FlagsAttribute() */ 
public enum DataGridViewDataErrorContexts
FlagsAttribute 
public enum DataGridViewDataErrorContexts
 Member nameDescription
ClipboardContentA data error occurred when copying content to the Clipboard. This value indicates that the cell value could not be converted to a string. 
CommitA data error occurred when committing changes to the data store. This value indicates that data entered in a cell could not be committed to the underlying data store. 
CurrentCellChangeA data error occurred when the selection cursor moved to another cell. This value indicates that a user selected a cell when the previously selected cell had an error condition. 
DisplayA data error occurred when displaying a cell that was populated by a data source. This value indicates that the value from the data source cannot be displayed by the cell, or a mapping that translates the value from the data source to the cell is missing. 
FormattingA data error occurred when trying to format data that is either being sent to a data store, or being loaded from a data store. This value indicates that a change to a cell failed to format correctly. Either the new cell value needs to be corrected or the cell's formatting needs to change. 
InitialValueRestorationA data error occurred when restoring a cell to its previous value. This value indicates that a cell tried to cancel an edit and the rollback to the initial value failed. This can occur if the cell formatting changed so that it is incompatible with the initial value. 
LeaveControlA data error occurred when the DataGridView lost focus. This value indicates that the DataGridView could not commit user changes after losing focus. 
ParsingA data error occurred when parsing new data. This value indicates that the DataGridView could not parse new data that was entered by the user or loaded from the underlying data store. 
PreferredSizeA data error occurred when calculating the preferred size of a cell. This value indicates that the DataGridView failed to calculate the preferred width or height of a cell when programmatically resizing a column or row. This can occur if the cell failed to format its value. 
RowDeletionA data error occurred when deleting a row. This value indicates that the underlying data store threw an exception when a data-bound DataGridView deleted a row. 
ScrollA data error occurred when scrolling a new region into view. This value indicates that a cell with data errors scrolled into view programmatically or with the scroll bar. 

Members of this enumeration may be combined using the bitwise OR operation to represent the state of a data-bound DataGridView when a data error occurred. For example, if a user enters an invalid cell value (such as entering a name in a cell that expects a date) and then selects a different cell, the DataGridView will try to commit the invalid cell value. When the commit fails, the DataGridView will raise a DataError event whose Context property will have a value of Commit and CurrentCellChange.

The following code example illustrates the use of this type. This example is part of a larger example available in How to: Handle Errors that Occur During Data Entry in the Windows Forms DataGridView Control.

private void dataGridView1_DataError(object sender,
    DataGridViewDataErrorEventArgs e)
{
    // If the data source raises an exception when a cell value is 
    // commited, display an error message.
    if (e.Exception != null &&
        e.Context == DataGridViewDataErrorContexts.Commit)
    {
        MessageBox.Show("CustomerID value must be unique.");
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.