| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Perform a Custom Action Based on Changes in a Cell of a Windows Forms DataGridView Control |
03/30/2017 |
.net-framework |
|
article |
|
|
7fa44d01-97f4-4ccb-a149-bc72628d2c36 |
13 |
dotnet-bot |
dotnetcontent |
wpickett |
How to: Perform a Custom Action Based on Changes in a Cell of a Windows Forms DataGridView Control
The xref:System.Windows.Forms.DataGridView control has a number of events you can use to detect changes in the state of xref:System.Windows.Forms.DataGridView cells. Two of the most commonly used are the xref:System.Windows.Forms.DataGridView.CellValueChanged and xref:System.Windows.Forms.DataGridView.CellStateChanged events.
To detect changes in the values of DataGridView cells
-
Write a handler for the xref:System.Windows.Forms.DataGridView.CellValueChanged event.
[!code-csharpSystem.Windows.Forms.DataGridViewMisc#130] [!code-vbSystem.Windows.Forms.DataGridViewMisc#130]
To detect changes in the states of DataGridView cells
-
Write a handler for the xref:System.Windows.Forms.DataGridView.CellStateChanged event.
[!code-csharpSystem.Windows.Forms.DataGridViewMisc#135] [!code-vbSystem.Windows.Forms.DataGridViewMisc#135]
Compiling the Code
This example requires:
-
A xref:System.Windows.Forms.DataGridView control named
dataGridView1. For C#, the event handlers must be connected to the corresponding events. -
References to the xref:System?displayProperty=nameWithType and xref:System.Windows.Forms?displayProperty=nameWithType assemblies.
See Also
xref:System.Windows.Forms.DataGridView
xref:System.Windows.Forms.DataGridView.CellValueChanged?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridView.CellStateChanged?displayProperty=nameWithType
Programming with Cells, Rows, and Columns in the Windows Forms DataGridView Control
Walkthrough: Validating Data in the Windows Forms DataGridView Control