DataGridView.RowDirtyStateNeeded 事件

定义

在以下情况下发生:当 VirtualMode 控件的 DataGridView 属性为 true,并且 DataGridView 需要确定当前行是否有未提交的更改时。Occurs when the VirtualMode property of the DataGridView control is true and the DataGridView needs to determine whether the current row has uncommitted changes.

public:
 event System::Windows::Forms::QuestionEventHandler ^ RowDirtyStateNeeded;
public event System.Windows.Forms.QuestionEventHandler RowDirtyStateNeeded;
member this.RowDirtyStateNeeded : System.Windows.Forms.QuestionEventHandler 
Public Custom Event RowDirtyStateNeeded As QuestionEventHandler 

示例

下面的代码示例演示如何处理此事件以提供单元级提交范围,这意味着用户只能将更改还原为当前单元格。The following code example demonstrates how to handle this event to provide cell-level commit scope, meaning that the user can revert changes to the current cell only. 在单元级别提交范围内,仅当当前单元格有未提交的更改(而不是行中的任何单元格有未提交的更改时),才将行视为具有未提交的更改。In cell-level commit scope, the row is treated as having uncommitted changes only when the current cell has uncommitted changes, rather than when any cell in the row has uncommitted changes. 此示例是 [Walkthrough 中提供的一个更大示例的一部分:在 Windows 窗体 DataGridView 控件 @ no__t 中实现虚拟模式。This example is part of a larger example available in Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.

void dataGridView1_RowDirtyStateNeeded( Object^ /*sender*/,
    System::Windows::Forms::QuestionEventArgs^ e )
{
   if (  !rowScopeCommit )
   {
      
      // In cell-level commit scope, indicate whether the value
      // of the current cell has been modified.
      e->Response = this->dataGridView1->IsCurrentCellDirty;
   }
}


private void dataGridView1_RowDirtyStateNeeded(object sender,
    System.Windows.Forms.QuestionEventArgs e)
{
    if (!rowScopeCommit)
    {
        // In cell-level commit scope, indicate whether the value
        // of the current cell has been modified.
        e.Response = this.dataGridView1.IsCurrentCellDirty;
    }
}
Private Sub dataGridView1_RowDirtyStateNeeded(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.QuestionEventArgs) _
    Handles dataGridView1.RowDirtyStateNeeded

    If Not rowScopeCommit Then

        ' In cell-level commit scope, indicate whether the value
        ' of the current cell has been modified.
        e.Response = Me.dataGridView1.IsCurrentCellDirty

    End If

End Sub

注解

默认情况下,如果当前行中的任何单元格已被修改,则此事件会将 QuestionEventArgs.Response 属性设置为 trueBy default, this event sets the QuestionEventArgs.Response property to true if any cells in the current row have been modified. 这会导致在用户将编辑还原到行时出现 @no__t 0 事件。This causes the CancelRowEdit event to occur when the user reverts edits to a row. 当单元格处于编辑模式或超出编辑模式时,用户可以通过按 ESC 两次,将编辑还原到行。Users can revert edits to a row by pressing ESC twice when a cell is in edit mode or once outside of edit mode. 此事件可用于在虚拟模式下自定义提交范围,方法是将 QuestionEventArgs.Response 属性设置为正确的值,具体取决于所选的提交范围。This event can be used for customizing commit scope in virtual mode by setting the QuestionEventArgs.Response property to the correct value depending on the chosen commit scope.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

适用于

另请参阅