DataGridView.RowErrorTextNeeded DataGridView.RowErrorTextNeeded DataGridView.RowErrorTextNeeded DataGridView.RowErrorTextNeeded Event

定义

在需要某一行的错误文本时发生。Occurs when a row's error text is needed.

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 

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中, 事件处理程序报告RowErrorTextNeeded事件的发生。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. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。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.

若要运行示例代码, 请将其粘贴到包含名为DataGridView DataGridView1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type DataGridView named DataGridView1. 然后, 确保事件处理程序与RowErrorTextNeeded事件相关联。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

注解

RowErrorTextNeeded当设置了DataGridView控件的DataSource属性或其VirtualMode属性为true时,才会发生此事件。The RowErrorTextNeeded event occurs only when the DataSource property of the DataGridView control is set or its VirtualMode property is true. 如果要根据行的状态和其包含的值确定行的错误,则处理事件会很有用。RowErrorTextNeededHandling the RowErrorTextNeeded event is useful when you want to determine the error for a row depending on its state and the values it contains.

处理RowErrorTextNeeded事件并在处理程序中指定错误文本时, ShowRowErrors除非将属性设置为false,否则行标题中将显示错误标志符号。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.

如果RowErrorTextNeeded检索DataGridViewRow.ErrorText属性的值,也会发生该事件。The RowErrorTextNeeded event also occurs whenever the value of the DataGridViewRow.ErrorText property is retrieved.

您可以使用DataGridViewRowErrorTextNeededEventArgs.RowIndex属性来确定行的状态或它包含的值,并使用此信息来更改或DataGridViewRowErrorTextNeededEventArgs.ErrorText修改属性。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. 此属性将用行ErrorText属性的值进行初始化,该属性的值将重写。This property is initialized with the value of the row ErrorText property, which the event value overrides.

处理大量数据时处理ErrorText 事件,以避免设置多行的行值时的性能损失。RowErrorTextNeededHandle the RowErrorTextNeeded event when working with large amounts of data to avoid the performance penalties of setting the row ErrorText value for multiple rows. 有关详细信息,请参阅 缩放 Windows 窗体 DataGridView 控件的最佳做法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.

适用于

另请参阅