The DataGridView.CellErrorTextNeeded event occurs only when the System.Windows.Forms.DataGridView control DataGridView.DataSource property is set or its DataGridView.VirtualMode property is true. Handling the DataGridView.CellErrorTextNeeded event is useful when you want to determine the error for a cell depending on its value or state.
When you handle the DataGridView.CellErrorTextNeeded event and specify error text in the handler, an error glyph appears in the cell unless the DataGridView.ShowCellErrors property is set to false or the cell is in edit mode. When the user moves the mouse pointer over the error glyph, the error text appears in a ToolTip.
You can use the DataGridViewCellEventArgs.RowIndex and DataGridViewCellEventArgs.ColumnIndex property to determine the state or value of a cell, and use this information to change or modify the DataGridViewCellErrorTextNeededEventArgs.ErrorText property. This property is initialized with the value of the cell DataGridViewCell.ErrorText property, which the event value overrides.
Handle the DataGridView.CellErrorTextNeeded event when working with large amounts of data to avoid the performance penalties of setting the cell DataGridViewCell.ErrorText value for multiple cells. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.
For more information about handling events, see Consuming Events.