If your data is read-only, the CellValueNeeded event may be the only event you will need to handle. Additional virtual-mode events let you enable specific functionality like user edits, row addition and deletion, and row-level transactions.
Some standard DataGridView events (such as events that occur when users add or delete rows, or when cell values are edited, parsed, validated, or formatted) are useful in virtual mode, as well. You can also handle events that let you maintain values not typically stored in a bound data source, such as cell ToolTip text, cell and row error text, cell and row shortcut menu data, and row height data.
For more information about implementing virtual mode to manage read/write data with a row-level commit scope, see Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.
For an example that implements virtual mode with a cell-level commit scope, see the VirtualMode property reference topic.
The following events occur only when the VirtualMode property is set to true.
Event | Description |
|---|
CellValueNeeded | Used by the control to retrieve a cell value from the data cache for display. This event occurs only for cells in unbound columns. |
CellValuePushed | Used by the control to commit user input for a cell to the data cache. This event occurs only for cells in unbound columns. Call the UpdateCellValue method when changing a cached value outside of a CellValuePushed event handler to ensure that the current value is displayed in the control and to apply any automatic sizing modes currently in effect. |
NewRowNeeded | Used by the control to indicate the need for a new row in the data cache. |
RowDirtyStateNeeded | Used by the control to determine whether a row has any uncommitted changes. |
CancelRowEdit | Used by the control to indicate that a row should revert to its cached values. |
The following events are useful in virtual mode, but can be used regardless of the VirtualMode property setting.