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只有在設定控件DataSource屬性或其 VirtualMode 屬性為 true時,DataGridView才會發生此事件。 RowErrorTextNeeded當您想要根據數據列的狀態及其包含的值來判斷數據列的錯誤時,處理事件很有用。

當您處理 RowErrorTextNeeded 事件並在處理程式中指定錯誤文字時,除非 DataGridView.ShowRowErrors 屬性設定為 false,否則數據列標頭中會出現錯誤字元。 當使用者將滑鼠指標移至錯誤字元上方時,錯誤文字會出現在工具提示中。

RowErrorTextNeeded每當擷取屬性的值DataGridViewRow.ErrorText時,也會發生此事件。

您可以使用 RowIndex 屬性來判斷數據列的狀態或值,並使用這項資訊來變更或修改 ErrorText 屬性。 這個屬性會使用事件值所覆寫的數據列 ErrorText 屬性值初始化。

RowErrorTextNeeded處理大量數據時,請處理 事件,以避免設定多個數據列的數據列ErrorText值效能負面影響。 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

屬性

ErrorText

取得或設定資料列的錯誤文字。

RowIndex

取得引發 RowErrorTextNeeded 事件的資料列。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱