DataGridViewRowErrorTextNeededEventArgs 类

定义

RowErrorTextNeeded 控件的 DataGridView 事件提供数据。

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

示例

下面的代码示例演示如何使用此类型。 在此示例中,事件处理程序报告事件的发生情况 RowErrorTextNeeded 。 此报告可帮助你了解事件发生的时间,并可以帮助你进行调试。 若要报告多个事件或频繁发生的事件,请考虑将 ShowConsole.WriteLine 消息替换为 或将消息追加到多行 TextBox

若要运行示例代码,请将其粘贴到包含名为 DataGridView1的类型的DataGridView实例的项目中。 然后,确保事件处理程序与 RowErrorTextNeeded 事件相关联。

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仅当控件属性已设置或其VirtualMode属性为 trueDataGridViewDataSource,才会发生该事件。 RowErrorTextNeeded若要根据行的状态及其包含的值来确定行的错误时,处理事件非常有用。

处理 RowErrorTextNeeded 事件并在处理程序中指定错误文本时,行标题中会显示错误字形, DataGridView.ShowRowErrors 除非 属性设置为 false。 当用户将鼠标指针移到错误字形上时,错误文本将显示在工具提示中。

每当 RowErrorTextNeeded 检索属性的值时, DataGridViewRow.ErrorText 也会发生 该事件。

可以使用 RowIndex 属性来确定行的状态或值,并使用此信息来更改或修改属性 ErrorText 。 此属性使用事件值替代的行 ErrorText 属性的值进行初始化。

RowErrorTextNeeded处理大量数据时处理 事件,以避免为多行设置行ErrorText值而造成性能损失。 有关详细信息,请参阅 缩放 Windows 窗体 DataGridView 控件的最佳做法

有关如何处理事件的详细信息,请参阅 处理和引发事件

属性

ErrorText

获取或设置行的错误文本。

RowIndex

获取引发 RowErrorTextNeeded 事件的行。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅