DataGridViewRowErrorTextNeededEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供控制 RowErrorTextNeeded 事件 DataGridView 的資料。
public ref class DataGridViewRowErrorTextNeededEventArgs : EventArgs
public class DataGridViewRowErrorTextNeededEventArgs : EventArgs
type DataGridViewRowErrorTextNeededEventArgs = class
inherit EventArgs
Public Class DataGridViewRowErrorTextNeededEventArgs
Inherits EventArgs
- 繼承
範例
下列程式代碼範例示範此類型的用法。 在這個例子中,事件處理者會回報事件 RowErrorTextNeeded 的發生情況。 此報告能幫助您了解事件發生時間,並協助除錯。 若要報告多個事件或頻繁發生的事件,請考慮將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事件僅在DataSourceDataGridView控制屬性被設定VirtualMode或其性質為 true時發生。 當你想根據列的狀態和包含的值來判斷錯誤時,處理事件 RowErrorTextNeeded 很有用。
當你處理RowErrorTextNeeded事件並在處理器中指定錯誤文字時,除非將屬性設定為 false,否則DataGridView.ShowRowErrors列標頭會出現錯誤字形。 當使用者將滑鼠指標移到錯誤字形上時,錯誤文字會顯示在工具提示中。
當該房產價值DataGridViewRow.ErrorText被取得時,該RowErrorTextNeeded事件也會發生。
你可以利用該RowIndex屬性來判斷一列的狀態或值,並利用這些資訊來更改或修改屬性。ErrorText 此屬性以列屬性的值 ErrorText 初始化,事件值會覆蓋該值。
處理大量資料時處理 RowErrorTextNeeded 事件,以避免設定多列列值所帶來 ErrorText 的效能損失。 欲了解更多資訊,請參閱 Windows 表單 DataGridView 控制項縮放的最佳實務。
欲了解更多如何處理事件的資訊,請參閱 「處理與提升事件」。
屬性
| 名稱 | Description |
|---|---|
| ErrorText |
取得或設定該列的錯誤文字。 |
| RowIndex |
他會拿到引發事件的 RowErrorTextNeeded 爭議。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |