語言

DataGridView.RowErrorTextNeeded 活動

定義

當需要列的錯誤文字時會發生。

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 

事件類型

範例

以下程式碼範例展示了此成員的使用方式。 在這個例子中,事件處理者會回報事件 RowErrorTextNeeded 的發生情況。 此報告能幫助您了解事件發生時間,並協助除錯。 若要報告多個事件或頻繁發生的事件,請考慮將MessageBox.Show訊息替換Console.WriteLine為或附加於多行TextBox。

要執行範例程式碼,請將其貼到包含一個 DataGridView 名為 DataGridView1的實例的專案中。 然後確保事件處理程式與事件 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控制項的屬性DataGridView被設定VirtualMode或其性質為 true時發生。 當你想根據列的狀態和包含的值來判斷錯誤時,處理事件 RowErrorTextNeeded 很有用。

當你處理RowErrorTextNeeded事件並在處理器中指定錯誤文字時,除非將屬性設定為 ShowRowErrors,否則false列標頭會出現錯誤字形。 當使用者將滑鼠指標移到錯誤字形上時,錯誤文字會顯示在工具提示中。

當該房產價值RowErrorTextNeeded被取得時,該DataGridViewRow.ErrorText事件也會發生。

你可以利用這個 DataGridViewRowErrorTextNeededEventArgs.RowIndex 屬性來判斷一列的狀態或其所包含的值,並利用這些資訊來更改或修改該 DataGridViewRowErrorTextNeededEventArgs.ErrorText 屬性。 此屬性以列屬性的值 ErrorText 初始化,事件值會覆蓋該值。

處理大量資料時處理 RowErrorTextNeeded 事件,以避免設定多列列值所帶來 ErrorText 的效能損失。 欲了解更多資訊,請參閱 Windows 表單 DataGridView 控制項縮放的最佳實務。

欲了解更多如何處理事件的資訊,請參閱 「處理與提升事件」。

適用於

另請參閱