DataGridViewCellEventArgs 類別

定義

提供與儲存格和資料列作業相關之 DataGridView 事件的資料。

public ref class DataGridViewCellEventArgs : EventArgs
public class DataGridViewCellEventArgs : EventArgs
type DataGridViewCellEventArgs = class
    inherit EventArgs
Public Class DataGridViewCellEventArgs
Inherits EventArgs
繼承
DataGridViewCellEventArgs
衍生

範例

下列程式碼範例示範如何使用 CellMouseEnterCellMouseLeave 事件處理常式來判斷是否可以按一下儲存格。 此範例會更新每個 ToolTipText 屬性值,以公告目前的影像配置。 此程式碼是How to: Work with Image Columns in the Windows Forms DataGridView Control中較大範例的一部分。

void dataGridView1_CellMouseEnter( Object^ sender, DataGridViewCellEventArgs^ e )
{
   Bitmap^ markingUnderMouse = dynamic_cast<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);
   }
}

void ToolTip( DataGridViewCellEventArgs^ e, bool showTip )
{
   DataGridViewImageCell^ cell = dynamic_cast<DataGridViewImageCell^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]);
   DataGridViewImageColumn^ imageColumn = dynamic_cast<DataGridViewImageColumn^>(dataGridView1->Columns[ cell->ColumnIndex ]);
   if ( showTip )
         cell->ToolTipText = imageColumn->Description;
   else
   {
      cell->ToolTipText = String::Empty;
   }
}

void dataGridView1_CellMouseLeave( Object^ sender, DataGridViewCellEventArgs^ e )
{
   ToolTip( e, false );
   dataGridView1->Cursor = Cursors::Default;
}
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;
}
Private Sub dataGridView1_CellMouseEnter(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellMouseEnter

    Dim markingUnderMouse As Bitmap = _
        CType(dataGridView1.Rows(e.RowIndex). _
            Cells(e.ColumnIndex).Value, Bitmap)

    If markingUnderMouse Is blank Then
        dataGridView1.Cursor = Cursors.Default
    ElseIf markingUnderMouse Is o OrElse markingUnderMouse Is x Then
        dataGridView1.Cursor = Cursors.No
        ToolTip(e)
    End If
End Sub

Private Sub ToolTip( _
    ByVal e As DataGridViewCellEventArgs)

    Dim cell As DataGridViewImageCell = _
        CType(dataGridView1.Rows(e.RowIndex). _
        Cells(e.ColumnIndex), DataGridViewImageCell)
    Dim imageColumn As DataGridViewImageColumn = _
        CType(dataGridView1.Columns(cell.ColumnIndex), _
        DataGridViewImageColumn)

    cell.ToolTipText = imageColumn.Description
End Sub

Private Sub dataGridView1_CellMouseLeave(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellMouseLeave

    dataGridView1.Cursor = Cursors.Default
End Sub

備註

類別 DataGridViewCellEventArgs 提供下列 DataGridView 事件的資料:

建構函式

DataGridViewCellEventArgs(Int32, Int32)

初始化 DataGridViewCellEventArgs 類別的新執行個體。

屬性

ColumnIndex

取得值,指出發生事件之儲存格的資料行索引。

RowIndex

取得值,指出發生事件之儲存格的資料列索引。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱