DataGridView.CellMouseEnter Event

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

Occurs when the mouse pointer enters a cell.

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

public event DataGridViewCellEventHandler CellMouseEnter
/** @event */
public void add_CellMouseEnter (DataGridViewCellEventHandler value)

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

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

For more information about handling events, see Consuming Events.

The following code example shows a CellMouseEnter event handler in a Tic-Tac-Toe game implementation that uses image columns in a DataGridView control. The event handler uses the cell value to determine the cursor and ToolTip to display.

This code is part of a larger example shown in How to: Work with Image Columns in the Windows Forms DataGridView Control.

private void dataGridView1_CellMouseEnter(object sender,
    DataGridViewCellEventArgs e)
{
    Bitmap markingUnderMouse = (Bitmap)dataGridView1.
           Rows[e.RowIndex].
           Cells[e.ColumnIndex].Value;

    if (markingUnderMouse == blank)
    {
        dataGridView1.Cursor = Cursors.Default;
    }
    else if (markingUnderMouse == o || markingUnderMouse == x)
    {
        dataGridView1.Cursor = Cursors.No;
        ToolTip(e, true);
    }
}

private void ToolTip(DataGridViewCellEventArgs e, bool showTip)
{
    DataGridViewImageCell cell = (DataGridViewImageCell)
        dataGridView1
        .Rows[e.RowIndex].Cells[e.ColumnIndex];
    DataGridViewImageColumn imageColumn =
        (DataGridViewImageColumn)
        dataGridView1.Columns[cell.ColumnIndex];

    if (showTip) cell.ToolTipText = imageColumn.Description;
    else { cell.ToolTipText = String.Empty; }
}

private void dataGridView1_CellMouseLeave(object sender,
    DataGridViewCellEventArgs e)
{
    ToolTip(e, false);
    dataGridView1.Cursor = Cursors.Default;
}

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

Community Additions

ADD
Show: