DataGridView.RowLeave Event
Occurs when a row loses input focus and is no longer the current row.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
For more information about handling events, see Consuming Events.
The following code example illustrates how to handle this event to change the BackColor property of the cells in the current row. In this example, the background color is set in the RowEnter event, then reset to Empty on the RowLeave event. To run this example, paste the code into a form that contains a DataGridView named dataGridView1 and ensure that all events are associated with their event handlers.
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++) { dataGridView1[i, e.RowIndex].Style.BackColor = Color.Yellow; } } private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e) { for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++) { dataGridView1[i, e.RowIndex].Style.BackColor = Color.Empty; } }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.