DataGridView.RowErrorTextNeeded Event

Definition

Occurs when a row's error text is needed.

public:
 event System::Windows::Forms::DataGridViewRowErrorTextNeededEventHandler ^ RowErrorTextNeeded;
public event System.Windows.Forms.DataGridViewRowErrorTextNeededEventHandler RowErrorTextNeeded;
public event System.Windows.Forms.DataGridViewRowErrorTextNeededEventHandler? RowErrorTextNeeded;
member this.RowErrorTextNeeded : System.Windows.Forms.DataGridViewRowErrorTextNeededEventHandler 
Public Custom Event RowErrorTextNeeded As DataGridViewRowErrorTextNeededEventHandler 

Event Type

Examples

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the RowErrorTextNeeded event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

To run the example code, paste it into a project that contains an instance of type DataGridView named DataGridView1. Then ensure that the event handler is associated with the RowErrorTextNeeded event.

private void DataGridView1_RowErrorTextNeeded(Object sender, DataGridViewRowErrorTextNeededEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ErrorText", e.ErrorText );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "RowErrorTextNeeded Event" );
}
Private Sub DataGridView1_RowErrorTextNeeded(sender as Object, e as DataGridViewRowErrorTextNeededEventArgs) _ 
     Handles DataGridView1.RowErrorTextNeeded

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ErrorText", e.ErrorText)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"RowErrorTextNeeded Event")

End Sub

Remarks

The RowErrorTextNeeded event occurs only when the DataSource property of the DataGridView control is set or its VirtualMode property is true. Handling the RowErrorTextNeeded event is useful when you want to determine the error for a row depending on its state and the values it contains.

When you handle the RowErrorTextNeeded event and specify error text in the handler, an error glyph appears in the row header unless the ShowRowErrors property is set to false. When the user moves the mouse pointer over the error glyph, the error text appears in a ToolTip.

The RowErrorTextNeeded event also occurs whenever the value of the DataGridViewRow.ErrorText property is retrieved.

You can use the DataGridViewRowErrorTextNeededEventArgs.RowIndex property to determine the state of a row or the values it contains, and use this information to change or modify the DataGridViewRowErrorTextNeededEventArgs.ErrorText property. This property is initialized with the value of the row ErrorText property, which the event value overrides.

Handle the RowErrorTextNeeded event when working with large amounts of data to avoid the performance penalties of setting the row ErrorText value for multiple rows. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

For more information about how to handle events, see Handling and Raising Events.

Applies to

See also