Export (0) Print
Expand All
Expand Minimize
3 out of 4 rated this helpful - Rate this topic

DataGridView.RowEnter Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when a row receives input focus and becomes the current row.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event DataGridViewCellEventHandler RowEnter
/** @event */
public void add_RowEnter (DataGridViewCellEventHandler value)

/** @event */
public void remove_RowEnter (DataGridViewCellEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

This event occurs when the DataGridView is initially loaded, as well as when the user selects a row other than the current row.

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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.