DataGridViewRowErrorTextNeededEventArgs 类


RowErrorTextNeeded 控件的 DataGridView 事件提供数据。Provides data for the RowErrorTextNeeded event of a DataGridView control.

public ref class DataGridViewRowErrorTextNeededEventArgs : EventArgs
public class DataGridViewRowErrorTextNeededEventArgs : EventArgs
type DataGridViewRowErrorTextNeededEventArgs = class
    inherit EventArgs
Public Class DataGridViewRowErrorTextNeededEventArgs
Inherits EventArgs


下面的代码示例演示如何使用此类型。The following code example demonstrates the use of this type. 在此示例中, 事件处理程序报告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. 若要报告多个事件或频繁发生的事件, 请考虑ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing 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.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
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.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    MessageBox.Show(messageBoxVB.ToString(),"RowErrorTextNeeded Event")

End Sub


RowErrorTextNeeded VirtualMode true当控件属性DataSource已设置或其属性为时, 才会发生此事件。 DataGridViewThe RowErrorTextNeeded event occurs only when the DataGridView control DataSource property 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事件并在处理程序中指定错误文本时, DataGridView.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 DataGridView.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.

您可以使用RowIndex属性来确定行的状态或值, 并使用此信息来更改或ErrorText修改属性。You can use the RowIndex property to determine the state or value of a row, and use this information to change or modify the 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.



获取或设置行的错误文本。Gets or sets the error text for the row.


获取引发 RowErrorTextNeeded 事件的行。Gets the row that raised the RowErrorTextNeeded event.



确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)